Commit 6966b002 authored by Fernando Herrero's avatar Fernando Herrero
Browse files

Merge branch 'packaging'

parents 77cb2c36 0d840c47
image: docker.io/labrobotica/labrobotica
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
- test
- deploy
build-package:
stage: build
script:
#- git submodule sync --recursive
#- git submodule update --init --recursive
- apt update
- apt -y install iri-iriutils-dev iri-comm-dev iri-dynamixel-dev
- apt -y install gcc-avr avr-libc #firmware dependencies
- mkdir -pv build
- cd build
- cmake -DCMAKE_BUILD_TYPE=RELEASE -DCPACK_PACKAGE_VERSION=$CI_COMMIT_TAG ..
- ls ..
- make firmware -j $(nproc)
- make package -j $(nproc)
artifacts:
paths:
- build/*.deb
expire_in: 2 weeks
only:
- tags
update_repo:
stage: deploy
script:
- cd build
- "scp -i /root/.ssh/iriLabKeyNopwd -r *battery-monitor*.deb irilabo@147.83.76.226:packages/"
- "ssh irilabo@147.83.76.226 -i /root/.ssh/iriLabKeyNopwd -tt /home/irilabo/repo_scripts/update_repo.sh battery-monitor"
only:
- tags
\ No newline at end of file
[submodule "avr8_smbus_battery_monitor"]
path = avr8_smbus_battery_monitor
url = ssh://git@gitlab.iri.upc.edu:2202/labrobotica/firmware/avr8_smbus_battery_monitor.git
branch = master
......@@ -9,6 +9,7 @@ endif(COMMAND cmake_policy)
# The project name and the type of project
PROJECT(battery_monitor)
SET(PACKAGE_NAME battery-monitor)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib)
......@@ -65,4 +66,34 @@ ELSE(UNIX)
)
ENDIF(UNIX)
IF (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86)|(X86)|(amd64)|(AMD64)")
SET (X86 TRUE)
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
ELSE ()
SET (X86 FALSE)
SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
ENDIF()
IF (UNIX)
SET(CPACK_PACKAGE_FILE_NAME "iri-${PACKAGE_NAME}-dev-${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
SET(CPACK_PACKAGE_NAME "iri-${PACKAGE_NAME}-dev")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Part of IRI-laboratory libraries. More information at https://gitlab.iri.upc.edu/labrobotica")
SET(CPACK_PACKAGING_INSTALL_PREFIX /usr)
SET(CPACK_GENERATOR "DEB")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "labrobotica - labrobotica@iri.upc.edu")
# Uncomment to add the necessary mantainer scripts
# SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/debian/preinst;${CMAKE_SOURCE_DIR}/scripts/debian/postinst;${CMAKE_SOURCE_DIR}/scripts/debian/prerm;${CMAKE_SOURCE_DIR}/scripts/debian/postrm")
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/scripts/debian/preinst;${CMAKE_SOURCE_DIR}/scripts/debian/postinst;${CMAKE_SOURCE_DIR}/scripts/debian/prerm;${CMAKE_SOURCE_DIR}/scripts/debian/postrm;${CMAKE_SOURCE_DIR}/scripts/load_pcspkr;${CMAKE_SOURCE_DIR}/scripts/undo_load_pcspkr.sh")
# Uncomment to add dependencies comma separated
# SET(CPACK_DEBIAN_PACKAGE_DEPENDS "iri-<package_name>-dev (>= 1.0~${DISTRIB})")
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "iri-iriutils-dev (>= 1.0~${DISTRIB}), iri-comm-dev (>= 1.0~${DISTRIB}), iri-dynamixel-dev (>= 1.0~${DISTRIB})")
INCLUDE(CPack)
ELSE(UNIX)
ADD_CUSTOM_COMMAND(
COMMENT "packaging only implemented in unix"
TARGET uninstall
)
ENDIF(UNIX)
\ No newline at end of file
#edit the following line to add the librarie's header files
FIND_PATH(battery_monitor_INCLUDE_DIR battery_monitor.h /usr/include/iri/battery_monitor /usr/local/include/iri/battery_monitor)
SET(name battery_monitor)
FIND_PATH(${name}_INCLUDE_DIRS ${name}.h /usr/include/iri/${name} /usr/local/include/iri/${name})
FIND_LIBRARY(battery_monitor_LIBRARY
NAMES battery_monitor
PATHS /usr/lib /usr/lib/iri/battery_monitor /usr/local/lib /usr/local/lib/iri/battery_monitor)
FIND_LIBRARY(${name}_LIBRARIES
NAMES ${name}
PATHS /usr/lib /usr/lib/iri/${name} /usr/local/lib /usr/local/lib/iri/${name})
SET(battery_monitor_INCLUDE_DIRS ${battery_monitor_INCLUDE_DIR})
SET(battery_monitor_LIBRARIES ${battery_monitor_LIBRARY})
SET(${name}_INCLUDE_DIR ${${name}_INCLUDE_DIRS})
SET(${name}_LIBRARY ${${name}_LIBRARIES})
IF (battery_monitor_INCLUDE_DIR AND battery_monitor_LIBRARY)
SET(battery_monitor_FOUND TRUE)
ENDIF (battery_monitor_INCLUDE_DIR AND battery_monitor_LIBRARY)
IF (${name}_INCLUDE_DIRS AND ${name}_LIBRARIES)
SET(${name}_FOUND TRUE)
ENDIF (${name}_INCLUDE_DIRS AND ${name}_LIBRARIES)
IF (battery_monitor_FOUND)
IF (NOT battery_monitor_FIND_QUIETLY)
MESSAGE(STATUS "Found battery_monitor: ${battery_monitor_LIBRARY}")
ENDIF (NOT battery_monitor_FIND_QUIETLY)
ELSE (battery_monitor_FOUND)
IF (battery_monitor_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find battery_monitor")
ENDIF (battery_monitor_FIND_REQUIRED)
ENDIF (battery_monitor_FOUND)
\ No newline at end of file
IF (${name}_FOUND)
IF (NOT ${name}_FIND_QUIETLY)
MESSAGE(STATUS "Found ${name}: ${${name}_LIBRARIES}")
ENDIF (NOT ${name}_FIND_QUIETLY)
ELSE (${name}_FOUND)
IF (${name}_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find ${name}")
ENDIF (${name}_FIND_REQUIRED)
ENDIF (${name}_FOUND)
battery_monitor library {#mainpage}
================
============
## Description
C++ driver to monitor the paylaod battery for the Tibi, Dabo and Teo platforms.
## Installation
* Add the labrobotica repository if it is not already added:
``` sudo sh -c 'echo "deb [arch=amd64] http://147.83.76.226/~irilabo/packages xenial main" > /etc/apt/sources.list.d/labrobotica_repo.list' ```
``` wget -O - http://147.83.76.226/~irilabo/labrobotica_repo.gpg.key | sudo apt-key add - ```
``` sudo apt update ```
* Install the package:
``` sudo apt install iri-battery-monitor-dev ```
## Important information
To use this driver is necessary to unload the *ftdi_sio* module, so the device is detected as a serial-usb device.
This can be achieved with the following command
```sudo rmmod ftdi_sio```
or executing the following script:
```unbind_ftdi_udev.sh -s <serial_number>```
## Disclaimer
Copyright (C) 20017-2019 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
Mantainer: IRI labrobotica (labrobotica@iri.upc.edu)
Author: shernand (shernand@iri.upc.edu)
All rights reserved.
This file is part of battery_monitor driver library
battery_monitor driver library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
## For developers
<details><summary>click here</summary>
<p>
## Dependencies
This package requires of the following system libraries and packages
......@@ -19,26 +73,31 @@ This package also requires of the following IRI libraries:
* [iriutils](https://gitlab.iri.upc.edu/labrobotica/algorithms/iriutils "iriutils gitlab page"), a set of basic tools.
* [comm](https://gitlab.iri.upc.edu/labrobotica/drivers/comm "comm gitlab page"), a set of drivers for standard communication devices.
* [dynamixel](https://gitlab.iri.upc.edu/labrobotica/drivers/dynamixel "dynamixel gitlab page"), a set of drivers for Dynamixel Bus communications
* [dynamixel](https://gitlab.iri.upc.edu/labrobotica/drivers/dynamixel "dynamixel gitlab page"), a driver for dynamixel communication protocol.
This package also contains the following packages as Git Submodules:
* [avr8_smbus_battery_monitor](https://gitlab.iri.upc.edu/labrobotica/firmware/avr8_smbus_battery_monitor), a firmware to read battery information through SMBUS
## Compilation and installation
Download this repository and create a build folder inside:
> ``` mkdir build ```
``` mkdir build ```
Inside the build folder execute the following commands:
> ``` cmake .. ```
``` cmake .. ```
The default build mode is DEBUG. That is, objects and executables include debug information.
The RELEASE build mode optimizes for speed. To build in this mode execute instead
> ``` cmake .. -DCMAKE_BUILD_TYPE=RELEASE ```
``` cmake .. -DCMAKE_BUILD_TYPE=RELEASE ```
The release mode will be kept until next time cmake is executed.
> ``` make ```
``` make -j $(nproc)```
In case no errors are reported, the generated libraries (if any) will be located at the
_lib_ folder and the executables (if any) will be located at the _bin_ folder.
......@@ -46,81 +105,55 @@ _lib_ folder and the executables (if any) will be located at the _bin_ folder.
In order to be able to use the library, it it necessary to copy it into the system.
To do that, execute
> ``` make install ```
``` make install ```
as root and the shared libraries will be copied to */usr/local/lib/iridrivers* directory
and the header files will be copied to */usr/local/include/iridrivers* dierctory. At
this point, the library may be used by any user.
as root and the shared libraries will be copied to */usr/local/lib/iri/battery_monitor* directory
and the header files will be copied to */usr/local/include/iri/battery_monitor* dierctory.
At this point, the library may be used by any user.
To remove the library from the system, exceute
> ``` make uninstall ```
``` make uninstall ```
as root, and all the associated files will be removed from the system.
To generate the documentation execute the following command:
> ``` make doc ```
## How to use it
### Test
A test example is provided, which will output the battery information on the screen.
First, you may need to:
* unload the *ftdi_sio* module, so the device is detected as a serial-usb device:
* Manually once:
``` sudo rmmod ftdi_sio```
* Persistently, you can run the provided script
```source scripts/unbind_ftdi_udev.sh```
``` make doc ```
* load the *pcspkr* module, so the motherboard buzzers makes sound when alarms are enabled:
### Scripts
* Manually once:
It's also needed to run some commands, gathered in this script:
``` sudo modprobe pcspkr```
* Load the *pcspkr* module, so the motherboard buzzers makes sound when alarms are enabled:
* Persistently, you can run the provided script:
```source scripts/load_pcspkr.sh```
Then you can run the example and see the battery status information on the screen
* Or manually once:
> ``` ./bin/battery_monitor_test```
``` sudo modprobe pcspkr```
### Library
## How to use it
To use this library in an other library or application, in the CMakeLists.txt file, first it is necessary to locate if the library has been installed or not using the following command
> ``` FIND_PACKAGE(<library name>) ```
``` FIND_PACKAGE(battery_monitor) ```
In the case that the package is present, it is necessary to add the header files directory to the include directory path by using
> ``` INCLUDE_DIRECTORIES(${<librray name>_INCLUDE_DIR}) ```
``` INCLUDE_DIRECTORIES(${battery_monitor_INCLUDE_DIRS}) ```
and it is also necessary to link with the desired libraries by using the following command
> ``` TARGET_LINK_LIBRARIES(<executable name> ${<library name>_LIBRARY}) ```
## Disclaimer
Copyright (C) 2009-2018 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
``` TARGET_LINK_LIBRARIES(<executable name> ${battery_monitor_LIBRARIES}) ```
Mantainer: IRI labrobotics (labrobotica@iri.upc.edu)
## Examples
Author: shernand (shernand@iri.upc.edu)
This package is distributed in the hope that it will be useful, but without any warranty. It is provided "as is" without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. The entire risk as to the quality and performance of the program is with you. should the program prove defective, the GMR group does not assume the cost of any necessary servicing, repair or correction.
In no event unless required by applicable law the author will be liable to you for damages, including any general, special, incidental or consequential damages arising out of the use or inability to use the program (including but not limited to loss of data or data being rendered inaccurate or losses sustained by you or third parties or a failure of the program to operate with any other programs), even if the author has been advised of the possibility of such damages.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
There is one example called _test\_battery\_monitor_, which prints the battery information on the screen.
```./bin/battery_monitor_test```
</p>
</details>
\ No newline at end of file
Subproject commit 09ac7168c041ef4fa6cfb9ad2daa314eb4c32684
Subproject commit aec8861f06509bf01008483d7f68abd4ad49b12f
#!/bin/bash
set -e
case "$1" in
configure)
#echo "Running postinst script"
# TEST
# echo "pkg name $DPKG_MAINTSCRIPT_PACKAGE"
# echo "pkg files: dpkg -L <pkg_name>"
# dpkg -L $DPKG_MAINTSCRIPT_PACKAGE
# TEST
#/usr/share/iri/battery_monitor/scripts/unbind_ftdi_udev.sh -s A600eB1Y
#/usr/share/iri/battery_monitor/scripts/unbind_ftdi_udev.sh -s A600eByq
#/usr/share/iri/battery_monitor/scripts/unbind_ftdi_udev.sh -s A900WSG1
# SERIAL DABO: A600eB1Y
# SERIAL TIBI: A600eByq
# SERIAL TEO: A900WSG1
/var/lib/dpkg/info/iri-battery-monitor-dev.load_pcspkr
;;
abort-upgrade)
;;
abort-remove)
;;
abort-deconfigure)
;;
esac
exit 0
\ No newline at end of file
#!/bin/bash
set -e
case "$1" in
remove)
# echo "Running postrm script"
;;
purge)
;;
upgrade)
;;
disappear)
;;
failed-upgrade)
;;
abort-install)
;;
abort-upgrade)
;;
esac
exit 0
#!/bin/bash
set -e
case "$1" in
install)
#echo "I'm a preinst script"
;;
upgrade)
;;
abort-upgrade)
;;
esac
exit 0
#!/bin/bash
set -e
case "$1" in
remove)
#echo "Running prerm script"
# TEST
# echo "pkg name $DPKG_MAINTSCRIPT_PACKAGE"
# echo "pkg files: dpkg -L <pkg_name>"
# dpkg -L $DPKG_MAINTSCRIPT_PACKAGE
# TEST
#/usr/share/iri/undo_unbind_ftdi_udev.sh -s A600eB1Y
#/usr/share/iri/undo_unbind_ftdi_udev.sh -s A600eByq
#/usr/share/iri/undo_unbind_ftdi_udev.sh -s A900WSG1
# SERIAL DABO: A600eB1Y
# SERIAL TIBI: A600eByq
# SERIAL TEO: A900WSG1
echo "You may want to remove pcspkr from /etc/modules, which was added when this package was installed."
#/var/lib/dpkg/info/iri-battery-monitor-dev.load_pcspkr
;;
upgrade)
;;
deconfigure)
;;
failed-upgrade)
;;
esac
exit 0
#!/bin/sh
echo "--- load_pcspkr.sh ---"
echo "Add pcspkr module to /etc/modules so it is loaded on startup"
LINE='pcspkr'
......
echo "battery_monitor_test: setting example privileges (needs sudo)"
sudo chown root:audio bin/battery_monitor_test
sudo chmod u+s bin/battery_monitor_test
sudo chmod u+s bin/battery_monitor_test
\ No newline at end of file
#!/bin/sh
VENDOR=${1:-0403}
PRODUCT=${2:-6001}
FILE=${3:-99-ftdi.rules}
echo "Add udev rule so ${VENDOR}:${PRODUCT} devices do not load ftdi_sio driver"
LINE0="#The following 2 lines make ${VENDOR}:${PRODUCT} devices not load ftdi_sio driver"
LINE1="ATTRS{idVendor}==\"${VENDOR}\", ATTRS{idProduct}==\"${PRODUCT}\", MODE:=\"0666\""
LINE2=$"ATTRS{idVendor}==\"${VENDOR}\", ATTRS{idProduct}==\"${PRODUCT}\", RUN+=\"/bin/sh -c 'echo \$kernel > /sys/bus/usb/drivers/ftdi_sio/unbind'\""
FILE=/etc/udev/rules.d/$FILE
sudo touch $FILE
grep -qF -- "$LINE0" "$FILE" || echo "$LINE0" | sudo tee -a "$FILE" > /dev/null
grep -qF -- "$LINE1" "$FILE" || echo "$LINE1" | sudo tee -a "$FILE" > /dev/null
grep -qF -- "$LINE2" "$FILE" || echo "$LINE2" | sudo tee -a "$FILE" > /dev/null
sudo service udev restart
echo "Need to unplug-plug devices for changes to take effect"
\ No newline at end of file
#!/bin/sh
echo "Remove pcspkr module from /etc/modules"
LINE="pcspkr"
FILE=/etc/modules
sudo sed -i "/$LINE/d" $FILE
sudo rmmod pcspkr
\ No newline at end of file
# driver source files
SET(sources battery_monitor.cpp)
# application header files
SET(headers battery_monitor.h)
SET(headers ../include/battery_monitor.h)
# locate the necessary dependencies
FIND_PACKAGE(iriutils REQUIRED)
......@@ -9,17 +9,17 @@ FIND_PACKAGE(comm REQUIRED)
FIND_PACKAGE(dynamixel REQUIRED)
# add the necessary include directories
INCLUDE_DIRECTORIES(.)
INCLUDE_DIRECTORIES(${iriutils_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${comm_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${dynamixel_INCLUDE_DIR})
INCLUDE_DIRECTORIES(../include)
INCLUDE_DIRECTORIES(${iriutils_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${comm_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${dynamixel_INCLUDE_DIRS})
# create the shared library
ADD_LIBRARY(battery_monitor SHARED ${sources})
TARGET_LINK_LIBRARIES(battery_monitor ${iriutils_LIBRARY})
TARGET_LINK_LIBRARIES(battery_monitor ${comm_LIBRARY})
TARGET_LINK_LIBRARIES(battery_monitor ${dynamixel_LIBRARY})
TARGET_LINK_LIBRARIES(battery_monitor ${iriutils_LIBRARIES})
TARGET_LINK_LIBRARIES(battery_monitor ${comm_LIBRARIES})
TARGET_LINK_LIBRARIES(battery_monitor ${dynamixel_LIBRARIES})
# link necessary libraries
INSTALL(TARGETS battery_monitor
......@@ -28,4 +28,39 @@ INSTALL(TARGETS battery_monitor
ARCHIVE DESTINATION lib/iri/${PROJECT_NAME})
INSTALL(FILES ${headers} DESTINATION include/iri/${PROJECT_NAME})
INSTALL(FILES ../Findbattery_monitor.cmake DESTINATION ${CMAKE_ROOT}/Modules/)
INSTALL(FILES ../scripts/load_pcspkr
../scripts/undo_load_pcspkr
DESTINATION share/iri
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ)
ADD_SUBDIRECTORY(examples)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
# Update submodules as needed
option(GIT_SUBMODULE "Check submodules during build" ON)
if(GIT_SUBMODULE)
message(STATUS "Submodule update")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT)
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
endif()
endif()
SET(firmware_dir avr8_smbus_battery_monitor)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/${firmware_dir}/Makefile")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif()
add_custom_target(firmware COMMAND make
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../${firmware_dir}
)
INSTALL(FILES
${CMAKE_CURRENT_SOURCE_DIR}/../${firmware_dir}/avr8_battery_monitor_eeprom.hex
${CMAKE_CURRENT_SOURCE_DIR}/../${firmware_dir}/avr8_battery_monitor.hex
DESTINATION lib/firmware/iri/${PROJECT_NAME}
OPTIONAL)
......@@ -4,6 +4,6 @@ ADD_EXECUTABLE(battery_monitor_test battery_monitor_test.cpp)
TARGET_LINK_LIBRARIES(battery_monitor_test battery_monitor)
add_custom_command(TARGET battery_monitor_test POST_BUILD
COMMAND sh ./privileges.sh
COMMAND sh ./scripts/set_example_privileges.sh
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment