mirror of
https://github.com/eclipse/upm.git
synced 2025-07-07 20:31:13 +03:00
Compare commits
110 Commits
Author | SHA1 | Date | |
---|---|---|---|
d355f76226 | |||
4f6be750c7 | |||
bf7d7d1bda | |||
9acc752074 | |||
b6b7d892c2 | |||
1ca8d100ea | |||
96f1afffe3 | |||
899d873cbc | |||
dc8be495a9 | |||
c7b5204fe4 | |||
527615758a | |||
16b6fcf807 | |||
5a9f234a3e | |||
c7bd37b322 | |||
edcaed90e6 | |||
655ccee9af | |||
102d86870a | |||
a88ec4237d | |||
cf2b8c9a6e | |||
68aa067f82 | |||
24062f6a9d | |||
db8d708798 | |||
edfdf6ec34 | |||
7c66d5c321 | |||
0e365590c4 | |||
ba127ec4d4 | |||
b6572e1f28 | |||
02974f242e | |||
e809016152 | |||
39c55b23d9 | |||
09b0f0adaa | |||
00b0092fc1 | |||
ec85072011 | |||
60221dbcd6 | |||
a35e58c54c | |||
1b8cb1361c | |||
aeb948282a | |||
1b649021f1 | |||
10d784ea7e | |||
a48f457057 | |||
d8fc664178 | |||
83b0512ffb | |||
3e7fca21ee | |||
8c7d6483d3 | |||
22636fb47a | |||
fb5c809ff8 | |||
0d20cdb25a | |||
f2b10afa35 | |||
56e1d2214f | |||
e80e1bda2c | |||
98f9dc54ff | |||
611f72c491 | |||
6f68e07aa5 | |||
be34f53a51 | |||
7a133cf891 | |||
49611e5ac0 | |||
e5385eb510 | |||
de1a46aa59 | |||
7e402ede34 | |||
4381f8bd2e | |||
757104e013 | |||
6c08313cb7 | |||
6d4714df3c | |||
75e42c6731 | |||
5a5637a431 | |||
e062b9b85c | |||
b778476597 | |||
9fb4be1b44 | |||
42ff8b3a6e | |||
a8d96bd2d9 | |||
f3a2e0d77c | |||
a348f23a3b | |||
efe80a4450 | |||
411656d965 | |||
c007385847 | |||
8490a63309 | |||
2331548f25 | |||
777f081f84 | |||
56666872d9 | |||
c16f80f226 | |||
ee8433d92a | |||
dd3e88fa59 | |||
224fe03d98 | |||
9e7eae070a | |||
9bc3d2ded0 | |||
f268437cd5 | |||
aff6e9c77f | |||
d642d63d21 | |||
17fd502cb5 | |||
b08da722f7 | |||
4220dd25b4 | |||
bbdbe56355 | |||
e7a5118f86 | |||
fe8906fb51 | |||
f35f6cc064 | |||
389bd32f81 | |||
f2b8921f1e | |||
6f080db5cb | |||
4aeccf7714 | |||
33734dc2e2 | |||
1f1a1bce8e | |||
bd7930f249 | |||
d183c9574d | |||
63066bcc0b | |||
15d91d4797 | |||
031ed7bf95 | |||
1aa445b74e | |||
e6ad752a2c | |||
144937995c | |||
0b49cbab9b |
33
.travis.yml
33
.travis.yml
@ -1,21 +1,38 @@
|
|||||||
language: cpp
|
language: cpp
|
||||||
compiler:
|
env:
|
||||||
- gcc
|
- CC=gcc CXX=gcc
|
||||||
- clang
|
- CC=clang CXX=clang++
|
||||||
|
- NODE4=true
|
||||||
|
- NODE5=true
|
||||||
|
- NODE012=true
|
||||||
install:
|
install:
|
||||||
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
|
||||||
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
- sudo add-apt-repository --yes ppa:fenics-packages/fenics-exp/swig
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -y -qq swig3.0 python git cmake
|
- sudo apt-get install -y -qq swig3.0 git
|
||||||
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
- sudo ln -s /usr/bin/swig3.0 /usr/bin/swig
|
||||||
- sudo update-java-alternatives -s java-8-oracle
|
- sudo update-java-alternatives -s java-8-oracle
|
||||||
before_script:
|
before_script:
|
||||||
|
- export NODE_ROOT_DIR="/home/travis/.nvm/v0.10.36"
|
||||||
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
- if [ "$CC" = "gcc" ]; then export BUILDJAVA=ON; else export BUILDJAVA=OFF; fi
|
||||||
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
- export JAVA_HOME=/usr/lib/jvm/java-8-oracle
|
||||||
|
- if [ "${NODE4}" ]; then nvm install 4.1; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
|
- if [ "${NODE5}" ]; then nvm install 5; export CC=gcc-4.8; export CXX=g++-4.8; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
|
- if [ "${NODE012}" ]; then nvm install 0.12; export NODE_ROOT_DIR="/home/travis/.nvm/versions/node/`nvm version`"; fi
|
||||||
script:
|
script:
|
||||||
- git clone --branch=master https://github.com/intel-iot-devkit/mraa.git
|
- git clone https://github.com/intel-iot-devkit/mraa.git
|
||||||
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include .. && make && make install
|
- cd mraa && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDSWIGNODE=OFF -DBUILDSWIGPYTHON=OFF -DFIRMATA=ON -DENABLEEXAMPLES=OFF -DCMAKE_INSTALL_PREFIX:PATH=. .. && make && make install
|
||||||
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
- export PKG_CONFIG_PATH=$PWD/lib/pkgconfig:$PWD/lib/x86_64-linux-gnu/pkgconfig
|
||||||
- export CPLUS_INCLUDE_PATH=$PWD/include
|
- export CPLUS_INCLUDE_PATH=$PWD/include
|
||||||
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
- export LIBRARY_PATH=$PWD/lib:$PWD/lib/x86_64-linux-gnu
|
||||||
- cd ../.. && mkdir build && cd build && cmake -DBUILDSWIGJAVA=$BUILDJAVA -DNODE_ROOT_DIR:PATH=/home/travis/.nvm/v0.10.36/include -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
- cd ../.. && mkdir build && cd build && cmake -DNODE_ROOT_DIR:PATH="${NODE_ROOT_DIR}" -DBUILDSWIGJAVA=$BUILDJAVA -DBUILDEXAMPLES=ON -DBUILDJAVAEXAMPLES=$BUILDJAVA .. && make
|
||||||
|
addons:
|
||||||
|
apt:
|
||||||
|
sources:
|
||||||
|
- llvm-toolchain-precise-3.6
|
||||||
|
- ubuntu-toolchain-r-test
|
||||||
|
- george-edison55-precise-backports
|
||||||
|
packages:
|
||||||
|
- clang-3.6
|
||||||
|
- g++-4.8
|
||||||
|
- cmake
|
||||||
|
- cmake-data
|
||||||
|
@ -15,17 +15,17 @@ message (INFO " found mraa version: ${MRAA_VERSION}")
|
|||||||
|
|
||||||
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
|
||||||
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
set (CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
|
||||||
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
|
|
||||||
|
|
||||||
# Set CMAKE_LIB_INSTALL_DIR if not defined
|
# Set CMAKE_INSTALL_LIBDIR if not defined
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
set (LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Installation path for libraries")
|
||||||
|
|
||||||
# Make a version file containing the current version from git.
|
# Make a version file containing the current version from git.
|
||||||
include (GetGitRevisionDescription)
|
include (GetGitRevisionDescription)
|
||||||
git_describe (VERSION "--tags")
|
git_describe (VERSION "--tags")
|
||||||
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
if ("x_${VERSION}" STREQUAL "x_GIT-NOTFOUND" OR "x_${VERSION}" STREQUAL "x_-128-NOTFOUND")
|
||||||
message (WARNING " - Install git to compile a production UPM!")
|
message (WARNING " - Install git to compile a production UPM!")
|
||||||
set (VERSION "v0.5.1-dirty")
|
set (VERSION "v0.6.2-dirty")
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
message (INFO " - UPM Version ${VERSION}")
|
message (INFO " - UPM Version ${VERSION}")
|
||||||
@ -51,13 +51,15 @@ set (CMAKE_SWIG_FLAGS "")
|
|||||||
option (BUILDDOC "Build all doc." OFF)
|
option (BUILDDOC "Build all doc." OFF)
|
||||||
option (BUILDSWIG "Build swig modules." ON)
|
option (BUILDSWIG "Build swig modules." ON)
|
||||||
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
option (BUILDSWIGPYTHON "Build swig python modules." ON)
|
||||||
|
option (BUILDPYTHON3 "Use python3 for building/installing/testing" OFF)
|
||||||
option (BUILDSWIGNODE "Build swig node modules." ON)
|
option (BUILDSWIGNODE "Build swig node modules." ON)
|
||||||
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
option (BUILDEXAMPLES "Build C++ example binaries" OFF)
|
||||||
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
option (BUILDJAVAEXAMPLES "Build java example jars" OFF)
|
||||||
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
option (BUILDSWIGJAVA "Build swig java modules" OFF)
|
||||||
option (IPK "Generate IPK using CPack" OFF)
|
option (IPK "Generate IPK using CPack" OFF)
|
||||||
option (RPM "Generate RPM using CPack" OFF)
|
option (RPM "Generate RPM using CPack" OFF)
|
||||||
option (BUILDTESTS "Generate check-ups for upm" OFF)
|
option (BUILDTESTS "Generate check-ups for upm" ON)
|
||||||
|
option (ENABLECXX11 "Enable C++11 standards support" ON)
|
||||||
|
|
||||||
# Find swig
|
# Find swig
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIG)
|
||||||
@ -76,6 +78,27 @@ include (TargetArch)
|
|||||||
target_architecture (DETECTED_ARCH)
|
target_architecture (DETECTED_ARCH)
|
||||||
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
message( INFO " - Target arch is ${DETECTED_ARCH}")
|
||||||
|
|
||||||
|
# enable c++11 standards support
|
||||||
|
if (ENABLECXX11)
|
||||||
|
include(CheckCXXCompilerFlag)
|
||||||
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||||
|
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||||
|
if (COMPILER_SUPPORTS_CXX11)
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
|
elseif (COMPILER_SUPPORTS_CXX0X)
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
|
else()
|
||||||
|
message(WARNING "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please update your C++ compiler.")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
# 3.1+ uses this generic method to enable c++11
|
||||||
|
set (CMAKE_CXX_STANDARD 11)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(WARNING "Some modules require C++11 support, and may not build without it.")
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BUILDDOC)
|
if (BUILDDOC)
|
||||||
# Add a target to generate API documentation with Doxygen
|
# Add a target to generate API documentation with Doxygen
|
||||||
find_package (Doxygen)
|
find_package (Doxygen)
|
||||||
@ -99,11 +122,10 @@ if (BUILDDOC)
|
|||||||
find_package (Sphinx)
|
find_package (Sphinx)
|
||||||
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
if(SPHINX_FOUND AND BUILDSWIG AND BUILDSWIGPYTHON)
|
||||||
# Python required for Sphinx build
|
# Python required for Sphinx build
|
||||||
find_package (PythonLibs)
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||||
set (SITE_PACKAGES ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)
|
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/conf.py.in ${CMAKE_CURRENT_BINARY_DIR}/pydoc/conf.py @ONLY)
|
||||||
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
|
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/doxy/index.rst ${CMAKE_CURRENT_BINARY_DIR}/pydoc/index.rst COPYONLY)
|
||||||
add_custom_target (pydoc ALL
|
add_custom_target (pydoc ALL
|
||||||
@ -130,9 +152,9 @@ if (BUILDDOC)
|
|||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy/node/${JSDOC_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${JSDOC_FILE} COPYONLY)
|
||||||
endforeach()
|
endforeach()
|
||||||
add_custom_target(jsdoc ALL
|
add_custom_target(jsdoc ALL
|
||||||
COMMAND ${NODE_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
COMMAND ${NODEJS_EXECUTABLE} docgen -m upm -i xml -t ${CMAKE_CURRENT_SOURCE_DIR}/src -g ../../
|
||||||
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
COMMAND ${YUIDOC_EXECUTABLE} -C --no-sort --helpers generators/yuidoc/helper.js --themedir generators/yuidoc/tmpl -o html/node jsdoc/yuidoc/upm
|
||||||
COMMAND ${NODE_EXECUTABLE} tolower -i html/node
|
COMMAND ${NODEJS_EXECUTABLE} tolower -i html/node
|
||||||
DEPENDS doc
|
DEPENDS doc
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
COMMENT "Generating API documentation with Yuidoc" VERBATIM
|
||||||
@ -156,7 +178,7 @@ if (IPK)
|
|||||||
endif ()
|
endif ()
|
||||||
message (INFO " - Package arch is ${TARGET_ARCH}")
|
message (INFO " - Package arch is ${TARGET_ARCH}")
|
||||||
|
|
||||||
set(CPACK_GENERATOR "DEB" "TGZ")
|
set(CPACK_GENERATOR "DEB")
|
||||||
set(OPKG_ARCH ${TARGET_ARCH})
|
set(OPKG_ARCH ${TARGET_ARCH})
|
||||||
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
set(CPACK_BINARY_DIR ${CMAKE_BINARY_DIR})
|
||||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Intel IoT-Devkit") #required
|
||||||
@ -182,21 +204,25 @@ if (RPM)
|
|||||||
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
message (INFO " - RPM packaging enabled for ${DETECTED_ARCH}")
|
||||||
set(CPACK_PACKAGE_VERSION ${VERSION})
|
set(CPACK_PACKAGE_VERSION ${VERSION})
|
||||||
set(CPACK_GENERATOR "RPM")
|
set(CPACK_GENERATOR "RPM")
|
||||||
set(CPACK_PACKAGE_NAME "libupm${upm_VERSION_MAJOR}")
|
set(CPACK_PACKAGE_NAME "upm")
|
||||||
set(CPACK_PACKAGE_RELEASE 1)
|
set(upm_PACKAGE_ON_TAG ".")
|
||||||
|
if ("${VERSION_COMMIT}" STREQUAL "")
|
||||||
|
set(upm_PACKAGE_ON_TAG "")
|
||||||
|
endif()
|
||||||
set(CPACK_PACKAGE_VERSION
|
set(CPACK_PACKAGE_VERSION
|
||||||
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}-${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
"${upm_VERSION_MAJOR}.${upm_VERSION_MINOR}.${upm_VERSION_PATCH}${upm_PACKAGE_ON_TAG}${VERSION_COMMIT}")
|
||||||
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
set(CPACK_PACKAGE_CONTACT "Intel IoT-Devkit")
|
||||||
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
set(CPACK_PACKAGE_VENDOR "Intel IoT-Devkit")
|
||||||
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
set(CPACK_RPM_PACKAGE_REQUIRES "mraa >= ${MRAA_VERSION}")
|
||||||
set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
|
set(CPACK_RPM_PACKAGE_PROVIDES "${CPACK_PACKAGE_NAME}-devel")
|
||||||
|
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
|
||||||
EXECUTE_PROCESS(COMMAND rpm --showrc
|
EXECUTE_PROCESS(COMMAND rpm --showrc
|
||||||
COMMAND grep -E "dist[[:space:]]*\\."
|
COMMAND grep -E "dist[[:space:]]*\\."
|
||||||
COMMAND sed -e "s/^.*dist\\s*\\.//"
|
COMMAND sed -e "s/^.*dist\\s*\\.//"
|
||||||
COMMAND tr \\n \\t
|
COMMAND tr \\n \\t
|
||||||
COMMAND sed -e s/\\t//
|
COMMAND sed -e s/\\t//
|
||||||
OUTPUT_VARIABLE DIST_TAG)
|
OUTPUT_VARIABLE DIST_TAG)
|
||||||
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${DIST_TAG}.${DETECTED_ARCH}")
|
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${DIST_TAG}.${DETECTED_ARCH}")
|
||||||
include(CPack)
|
include(CPack)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -210,10 +236,16 @@ if(BUILDJAVAEXAMPLES)
|
|||||||
add_subdirectory (examples/java)
|
add_subdirectory (examples/java)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BUILDTESTS)
|
if (BUILDSWIGPYTHON OR BUILDTESTS)
|
||||||
find_package (PythonInterp REQUIRED)
|
if (BUILDPYTHON3)
|
||||||
if (${PYTHONINTERP_FOUND})
|
set (PYTHONBUILD_VERSION 3)
|
||||||
|
else ()
|
||||||
|
set (PYTHONBUILD_VERSION 2.7)
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (BUILDTESTS)
|
||||||
|
find_package (PythonInterp ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
enable_testing ()
|
enable_testing ()
|
||||||
add_subdirectory (tests)
|
add_subdirectory (tests)
|
||||||
endif ()
|
|
||||||
endif()
|
endif()
|
||||||
|
28
README.md
28
README.md
@ -12,6 +12,19 @@ to provide identification/pin location on the board.
|
|||||||
Typically an update() function will be called in order to get new data from the
|
Typically an update() function will be called in order to get new data from the
|
||||||
sensor in order to reduce load when doing multiple reads to sensor data.
|
sensor in order to reduce load when doing multiple reads to sensor data.
|
||||||
|
|
||||||
|
Although implementation and API design is up to the developer, C++ interfaces have
|
||||||
|
been defined for the following sensor/actuator types and developers are encouraged to
|
||||||
|
implement them. Interface header files are in the src/upm folder.
|
||||||
|
|
||||||
|
* Light controller
|
||||||
|
* Light sensor
|
||||||
|
* Temperature sensor
|
||||||
|
* Humidity sensor
|
||||||
|
* Pressure sensor
|
||||||
|
* Analog to digital converter
|
||||||
|
|
||||||
|
Feedback on interface design and additions for new types are welcome
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
|
A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer API):
|
||||||
@ -51,10 +64,6 @@ A sensor/actuator is expected to work as such (here is the MMA7660 accelerometer
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
However implementation and API design is completely up to the developer, some
|
|
||||||
enumerable sensors for example may provide much clever instantiation. Displays
|
|
||||||
may also create more complex structures in order to interface with them.
|
|
||||||
|
|
||||||
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
|
Browse through the list of all [examples](https://github.com/intel-iot-devkit/upm/tree/master/examples).
|
||||||
|
|
||||||
Multi-sensor samples for the starter and specialized kits can be found in the
|
Multi-sensor samples for the starter and specialized kits can be found in the
|
||||||
@ -81,7 +90,7 @@ See building documentation [here](docs/building.md).
|
|||||||
|
|
||||||
Porting [link](docs/porting.md) has more information on making new UPM modules.
|
Porting [link](docs/porting.md) has more information on making new UPM modules.
|
||||||
|
|
||||||
There is also an example available for max31855 [sensor](docs/max31855.md).
|
There is also an example available gfor max31855 [sensor](docs/max31855.md).
|
||||||
|
|
||||||
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
Guide on creating Java [bindings](docs/creating_java_bindings.md).
|
||||||
|
|
||||||
@ -105,6 +114,15 @@ API Documentation
|
|||||||
<a href="http://iotdk.intel.com/docs/master/upm/python"><img src="docs/icons/python.png"/></a>
|
<a href="http://iotdk.intel.com/docs/master/upm/python"><img src="docs/icons/python.png"/></a>
|
||||||
<a href="http://iotdk.intel.com/docs/master/upm/node"><img src="docs/icons/node.png"/></a>
|
<a href="http://iotdk.intel.com/docs/master/upm/node"><img src="docs/icons/node.png"/></a>
|
||||||
|
|
||||||
|
### API Compatibility
|
||||||
|
Even if we try our best not to, every once in a while we are forced to modify
|
||||||
|
our API in a way that will break backwards compatibility. If you find yourself
|
||||||
|
unable to compile code that was working fine before a library update, make sure
|
||||||
|
you check the [API changes](docs/apichanges.md) section first.
|
||||||
|
|
||||||
|
**NOTE** - Our **C++ header files** will change their extension from *.h* to
|
||||||
|
*.hpp* in the upcoming version.
|
||||||
|
|
||||||
### Changelog
|
### Changelog
|
||||||
Version changelog [here](docs/changelog.md).
|
Version changelog [here](docs/changelog.md).
|
||||||
|
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
find_program (NODE_EXECUTABLE NAMES node
|
# Macro to add directory to NODEJS_INCLUDE_DIRS if it exists and is not /usr/include
|
||||||
|
macro(add_include_dir dir)
|
||||||
|
if (IS_DIRECTORY ${dir} AND NOT ${dir} STREQUAL "/usr/include")
|
||||||
|
set(NODEJS_INCLUDE_DIRS ${NODEJS_INCLUDE_DIRS} ${dir})
|
||||||
|
endif()
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
|
find_program (NODEJS_EXECUTABLE NAMES node nodejs
|
||||||
HINTS
|
HINTS
|
||||||
$ENV{NODE_DIR}
|
$ENV{NODE_DIR}
|
||||||
PATH_SUFFIXES bin
|
PATH_SUFFIXES bin
|
||||||
@ -7,26 +15,50 @@ find_program (NODE_EXECUTABLE NAMES node
|
|||||||
|
|
||||||
include (FindPackageHandleStandardArgs)
|
include (FindPackageHandleStandardArgs)
|
||||||
|
|
||||||
find_path (NODE_ROOT_DIR "node/node.h" "src/node.h"
|
# If compat-libuv package exists, it must be at start of include path
|
||||||
PATHS /usr/include/nodejs /usr/local/include/nodejs)
|
find_path (UV_ROOT_DIR "uv.h" PATHS /usr/include/compat-libuv010 NO_DEFAULT_PATH)
|
||||||
|
if (UV_ROOT_DIR)
|
||||||
|
# set (NODEJS_INCLUDE_DIRS ${UV_ROOT_DIR})
|
||||||
|
add_include_dir(${UV_ROOT_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
set (NODE_INCLUDE_DIRS
|
# Now look for node. Flag an error if not found
|
||||||
${NODE_ROOT_DIR}/src
|
find_path (NODE_ROOT_DIR "include/node/node.h" "include/src/node.h"
|
||||||
${NODE_ROOT_DIR}/node
|
PATHS /usr/include/nodejs /usr/local/include/nodejs /usr/local/include)
|
||||||
${NODE_ROOT_DIR}/deps/v8/include
|
if (NODE_ROOT_DIR)
|
||||||
${NODE_ROOT_DIR}/deps/uv/include
|
add_include_dir(${NODE_ROOT_DIR}/include/src)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/node)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/deps/v8/include)
|
||||||
|
add_include_dir(${NODE_ROOT_DIR}/include/deps/uv/include)
|
||||||
|
else()
|
||||||
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
|
message(ERROR " - node.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check that v8.h is in NODEJS_INCLUDE_DIRS
|
||||||
|
find_path (V8_ROOT_DIR "v8.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||||
|
if (NOT V8_ROOT_DIR)
|
||||||
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
|
message(ERROR " - v8.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Check that uv.h is in NODEJS_INCLUDE_DIRS
|
||||||
|
find_path (UV_ROOT_DIR "uv.h" PATHS ${NODEJS_INCLUDE_DIRS})
|
||||||
|
if (NOT UV_ROOT_DIR)
|
||||||
|
unset(NODEJS_INCLUDE_DIRS)
|
||||||
|
message(ERROR " - uv.h not found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package_handle_standard_args (Nodejs DEFAULT_MSG
|
||||||
|
NODEJS_EXECUTABLE
|
||||||
|
NODEJS_INCLUDE_DIRS
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package_handle_standard_args (Node DEFAULT_MSG
|
if (NODEJS_EXECUTABLE)
|
||||||
NODE_EXECUTABLE
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} --version
|
||||||
NODE_INCLUDE_DIRS
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NODE_EXECUTABLE)
|
|
||||||
execute_process(COMMAND ${NODE_EXECUTABLE} --version
|
|
||||||
OUTPUT_VARIABLE _VERSION
|
OUTPUT_VARIABLE _VERSION
|
||||||
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
RESULT_VARIABLE _NODE_VERSION_RESULT)
|
||||||
execute_process(COMMAND ${NODE_EXECUTABLE} -e "console.log(process.versions.v8)"
|
execute_process(COMMAND ${NODEJS_EXECUTABLE} -e "console.log(process.versions.v8)"
|
||||||
OUTPUT_VARIABLE _V8_VERSION
|
OUTPUT_VARIABLE _V8_VERSION
|
||||||
RESULT_VARIABLE _V8_RESULT)
|
RESULT_VARIABLE _V8_RESULT)
|
||||||
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
if (NOT _NODE_VERSION_RESULT AND NOT _V8_RESULT)
|
||||||
@ -55,7 +87,11 @@ if (NODE_EXECUTABLE)
|
|||||||
set (V8_VERSION_STRING "3.28.72")
|
set (V8_VERSION_STRING "3.28.72")
|
||||||
message ("defaulted to node 0.10.30")
|
message ("defaulted to node 0.10.30")
|
||||||
endif ()
|
endif ()
|
||||||
message ("INFO - Node version is " ${NODE_VERSION_STRING} "INFO - Node using v8 " ${V8_VERSION_STRING})
|
string (REGEX REPLACE "\n" "" NODE_VERSION_STRING ${NODE_VERSION_STRING})
|
||||||
|
string (REGEX REPLACE "\n" "" V8_VERSION_STRING ${V8_VERSION_STRING})
|
||||||
|
message ("INFO - Node version is " ${NODE_VERSION_STRING})
|
||||||
|
message ("INFO - Node using v8 " ${V8_VERSION_STRING})
|
||||||
|
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
mark_as_advanced (NODE_EXECUTABLE)
|
mark_as_advanced (NODEJS_EXECUTABLE)
|
||||||
|
20
docs/apichanges.md
Normal file
20
docs/apichanges.md
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
API Changes {#apichanges}
|
||||||
|
===============
|
||||||
|
|
||||||
|
**IMPORTANT NOTICE**
|
||||||
|
|
||||||
|
Our **C++ header files** will change their extension from *.h* to *.hpp*. This
|
||||||
|
change is anticipated in the upcoming version and unfortunately will break
|
||||||
|
source compatibility with previous versions of UPM for every library. You will
|
||||||
|
need to update your code and change to the new extension format in your
|
||||||
|
`#include` directives.
|
||||||
|
|
||||||
|
Here's a list of other API changes made to the library that break source/binary
|
||||||
|
compatibility between releases:
|
||||||
|
|
||||||
|
* **my9221**, **groveledbar** and **grovecircularled** are now all part of the
|
||||||
|
same library (my9221) and new functionality was added going to v.0.5.1
|
||||||
|
* **stepmotor** driver API was changed significantly from v.0.4.1 to v.0.5.0
|
||||||
|
* **eboled** library was greatly improved in version 0.4.0 and the `draw()`
|
||||||
|
function was removed in favor of a more complete GFX library implementation
|
||||||
|
|
@ -4,6 +4,38 @@ Changelog {#changelog}
|
|||||||
Here's a list summarizing some of the key undergoing changes to our library
|
Here's a list summarizing some of the key undergoing changes to our library
|
||||||
from earlier versions:
|
from earlier versions:
|
||||||
|
|
||||||
|
### v0.6.2
|
||||||
|
|
||||||
|
* Added a generic driver for taking snapshots from an USB camera device
|
||||||
|
* New API changes section in documentation to let users know when the UPM API
|
||||||
|
gets modified
|
||||||
|
* Fixed some spelling errors and improved JavaScript documentation builds with
|
||||||
|
newer versions of YUI and Node
|
||||||
|
* Enhanced Cmake scripts and the build process
|
||||||
|
* New sensors: vcap, e50hx
|
||||||
|
|
||||||
|
### v0.6.1
|
||||||
|
|
||||||
|
* Fixed library build process for different configurations across multiple
|
||||||
|
environments reported by users.
|
||||||
|
* Fixed multiple GFX library header clash and improved SSD1351 compatibility
|
||||||
|
by changing SPI mode
|
||||||
|
* Added Node and Python array typemaps for nrf24l01
|
||||||
|
* Added 2 new JAVA examples
|
||||||
|
|
||||||
|
### v0.6.0
|
||||||
|
|
||||||
|
* Introduced C++ Interfaces for several sensor categories that will help
|
||||||
|
consolidate the sensor APIs with uniform function names upon implementation
|
||||||
|
* Greatly improved Node.js detection and handling during build and install,
|
||||||
|
and should be now compatible with all major versions
|
||||||
|
* Added a driver for the Curie IMU (accelerometer + gyroscope) that works with
|
||||||
|
the new Firmata support implemented by MRAA
|
||||||
|
* Continued to provide several JAVA fixes and examples
|
||||||
|
* Many new industrial and maker sensors: cwlsxxa, teams, tex00, h803x, apa102,
|
||||||
|
smartdrive, bmi160, bme280, ds1808lc, hlg150, lp8860, max44009, si1132, t6713,
|
||||||
|
si7005, ssd1351
|
||||||
|
|
||||||
### v0.5.1
|
### v0.5.1
|
||||||
|
|
||||||
* Updated the API and added new functionality for the MY9221 class and derived
|
* Updated the API and added new functionality for the MY9221 class and derived
|
||||||
|
BIN
docs/images/apa102.jpg
Normal file
BIN
docs/images/apa102.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 72 KiB |
BIN
docs/images/ssd1351.jpg
Normal file
BIN
docs/images/ssd1351.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 90 KiB |
@ -859,7 +859,7 @@ EXCLUDE_SYMLINKS = NO
|
|||||||
# Note that the wildcards are matched against the file with absolute path, so to
|
# Note that the wildcards are matched against the file with absolute path, so to
|
||||||
# exclude all test directories for example use the pattern */test/*
|
# exclude all test directories for example use the pattern */test/*
|
||||||
|
|
||||||
EXCLUDE_PATTERNS =
|
EXCLUDE_PATTERNS = bosch_*
|
||||||
|
|
||||||
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
|
||||||
# (namespaces, classes, functions, etc.) that should be excluded from the
|
# (namespaces, classes, functions, etc.) that should be excluded from the
|
||||||
|
@ -48,7 +48,7 @@ mpu9150.cxx MPU9150Sample.java
|
|||||||
mq2.cxx MQ2Sample.java
|
mq2.cxx MQ2Sample.java
|
||||||
mq303a.cxx MQ303ASample.java
|
mq303a.cxx MQ303ASample.java
|
||||||
mq5.cxx MQ5Sample.java
|
mq5.cxx MQ5Sample.java
|
||||||
my9221-ledbar.cxx MY9221_ledbarSample.java
|
groveledbar GroveLEDBar
|
||||||
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
nrf24l01-receiver.cxx NRF24L01_receiverSample.java
|
||||||
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
nrf24l01-transmitter.cxx NRF24L01_transmitterSample.java
|
||||||
nunchuck.cxx NUNCHUCKSample.java
|
nunchuck.cxx NUNCHUCKSample.java
|
||||||
|
@ -234,11 +234,37 @@ if (MODBUS_FOUND)
|
|||||||
include_directories(${MODBUS_INCLUDE_DIRS})
|
include_directories(${MODBUS_INCLUDE_DIRS})
|
||||||
add_example (t3311)
|
add_example (t3311)
|
||||||
add_example (hwxpxx)
|
add_example (hwxpxx)
|
||||||
|
add_example (h803x)
|
||||||
endif()
|
endif()
|
||||||
add_example (hdxxvxta)
|
add_example (hdxxvxta)
|
||||||
add_example (rhusb)
|
add_example (rhusb)
|
||||||
add_example (apds9930)
|
add_example (apds9930)
|
||||||
add_example (kxcjk1013)
|
add_example (kxcjk1013)
|
||||||
|
add_example (ssd1351)
|
||||||
|
add_example (bme280)
|
||||||
|
add_example (ds1808lc)
|
||||||
|
add_example (hlg150h)
|
||||||
|
add_example (lp8860)
|
||||||
|
add_example (max44009)
|
||||||
|
add_example (si1132)
|
||||||
|
add_example (si7005)
|
||||||
|
add_example (t6713)
|
||||||
|
add_example (cwlsxxa)
|
||||||
|
add_example (teams)
|
||||||
|
add_example (apa102)
|
||||||
|
add_example (tex00)
|
||||||
|
add_example (bmi160)
|
||||||
|
add_example (smartdrive)
|
||||||
|
if (HAVE_FIRMATA)
|
||||||
|
add_example (curieimu)
|
||||||
|
endif ()
|
||||||
|
if (BACNET_FOUND)
|
||||||
|
include_directories(${BACNET_INCLUDE_DIRS})
|
||||||
|
# we need access to bacnetmstp headers too
|
||||||
|
include_directories(${PROJECT_SOURCE_DIR}/src/bacnetmstp)
|
||||||
|
add_example (e50hx)
|
||||||
|
endif()
|
||||||
|
add_example (vcap)
|
||||||
|
|
||||||
# These are special cases where you specify example binary, source file and module(s)
|
# These are special cases where you specify example binary, source file and module(s)
|
||||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||||
@ -257,3 +283,10 @@ add_custom_example (ak8975-example ak8975.cxx mpu9150)
|
|||||||
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
add_custom_example (mpu9250-example mpu9250.cxx mpu9150)
|
||||||
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
add_custom_example (groveledbar-example groveledbar.cxx my9221)
|
||||||
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
|
add_custom_example (grovecircularled-example grovecircularled.cxx my9221)
|
||||||
|
add_custom_example (temperature-sensor-example temperature-sensor.cxx "si7005;bmp180;bme280")
|
||||||
|
add_custom_example (humidity-sensor-example humidity-sensor.cxx "si7005;bme280")
|
||||||
|
add_custom_example (pressure-sensor-example pressure-sensor.cxx "bmp180;bme280")
|
||||||
|
add_custom_example (co2-sensor-example co2-sensor.cxx "t6713")
|
||||||
|
add_custom_example (adc-example adc-sensor.cxx "ads1x15")
|
||||||
|
add_custom_example (light-sensor-example light-sensor.cxx "si1132;max44009")
|
||||||
|
add_custom_example (light-controller-example light-controller.cxx "lp8860;ds1808lc;hlg150h")
|
||||||
|
80
examples/c++/adc-sensor.cxx
Normal file
80
examples/c++/adc-sensor.cxx
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "ads1015.h"
|
||||||
|
#include "mraa/gpio.hpp"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using IADC to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// IADC is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::IADC* getADC()
|
||||||
|
{
|
||||||
|
upm::IADC* adc = NULL;
|
||||||
|
try {
|
||||||
|
adc = new upm::ADS1015(EDISON_I2C_BUS);
|
||||||
|
mraa::Gpio gpio(EDISON_GPIO_SI7005_CS);
|
||||||
|
gpio.dir(mraa::DIR_OUT_HIGH);
|
||||||
|
return adc;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "ADS1015: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return adc;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::IADC* adc = getADC();
|
||||||
|
if (adc == NULL) {
|
||||||
|
std::cout << "ADC not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "ADC " << adc->getModuleName() << " detected. " ;
|
||||||
|
std::cout << adc->getNumInputs() << " inputs available" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
for (unsigned int i=0; i<adc->getNumInputs(); ++i) {
|
||||||
|
std::cout << "Input " << i;
|
||||||
|
try {
|
||||||
|
float voltage = adc->getVoltage(i);
|
||||||
|
std::cout << ": Voltage = " << voltage << "V" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete adc;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
@ -286,7 +286,7 @@ int main()
|
|||||||
else ads->setCompMode();
|
else ads->setCompMode();
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
cout << ads->getCompLatch() << cout;
|
cout << ads->getCompLatch() << endl;
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
@ -296,7 +296,7 @@ int main()
|
|||||||
else ads->setCompLatch();
|
else ads->setCompLatch();
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
cout << ads->getContinuous() << cout;
|
cout << ads->getContinuous() << endl;
|
||||||
break;
|
break;
|
||||||
case 21:
|
case 21:
|
||||||
cout << "select one of the following:" << endl;
|
cout << "select one of the following:" << endl;
|
||||||
|
51
examples/c++/apa102.cxx
Normal file
51
examples/c++/apa102.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "apa102.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
|
upm::APA102* ledStrip = new upm::APA102(800, 0);
|
||||||
|
|
||||||
|
// Set all LEDs to Red
|
||||||
|
ledStrip->setAllLeds(31, 255, 0, 0);
|
||||||
|
|
||||||
|
// Set a section (10 to 20) to blue
|
||||||
|
ledStrip->setLeds(10, 20, 31, 0, 0, 255);
|
||||||
|
|
||||||
|
// Set a single LED to green
|
||||||
|
ledStrip->setLed(15, 31, 0, 255, 0);
|
||||||
|
|
||||||
|
delete ledStrip;
|
||||||
|
//! [Interesting]
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/bme280.cxx
Normal file
51
examples/c++/bme280.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::BME280* bme280 = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
while (true) {
|
||||||
|
int temperature = bme280->getTemperatureCelcius();
|
||||||
|
int humidity = bme280->getHumidityRelative();
|
||||||
|
int pressure = bme280->getPressurePa();
|
||||||
|
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
||||||
|
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
||||||
|
std::cout << "Pressure = " << pressure << "Pa" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete bme280;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
82
examples/c++/bmi160.cxx
Normal file
82
examples/c++/bmi160.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include "bmi160.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
upm::BMI160 *sensor = new upm::BMI160();
|
||||||
|
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
float dataX, dataY, dataZ;
|
||||||
|
|
||||||
|
sensor->getAccelerometer(&dataX, &dataY, &dataZ);
|
||||||
|
cout << "Accelerometer: ";
|
||||||
|
cout << "AX: " << dataX << " AY: " << dataY << " AZ: "
|
||||||
|
<< dataZ << endl;
|
||||||
|
|
||||||
|
sensor->getGyroscope(&dataX, &dataY, &dataZ);
|
||||||
|
cout << "Gryoscope: ";
|
||||||
|
cout << "GX: " << dataX << " GY: " << dataY << " GZ: "
|
||||||
|
<< dataZ << endl;
|
||||||
|
|
||||||
|
sensor->getMagnetometer(&dataX, &dataY, &dataZ);
|
||||||
|
cout << "Magnetometer: ";
|
||||||
|
cout << "MX: " << dataX << " MY: " << dataY << " MZ: "
|
||||||
|
<< dataZ << endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
71
examples/c++/co2-sensor.cxx
Normal file
71
examples/c++/co2-sensor.cxx
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "t6713.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ICO2Sensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ICO2Sensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::ICO2Sensor* getCO2Sensor()
|
||||||
|
{
|
||||||
|
upm::ICO2Sensor* cO2Sensor = NULL;
|
||||||
|
try {
|
||||||
|
cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return cO2Sensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "T6713: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return cO2Sensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::ICO2Sensor* cO2Sensor = getCO2Sensor();
|
||||||
|
if (cO2Sensor == NULL) {
|
||||||
|
std::cout << "CO2 sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "CO2 sensor " << cO2Sensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
uint16_t value = cO2Sensor->getPpm();
|
||||||
|
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete cO2Sensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
81
examples/c++/curieimu.cxx
Normal file
81
examples/c++/curieimu.cxx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "curieimu.hpp"
|
||||||
|
#include "mraa.h"
|
||||||
|
#include "mraa/firmata.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
mraa_init();
|
||||||
|
mraa_add_subplatform(MRAA_GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
|
upm::CurieImu* sensor = new upm::CurieImu();
|
||||||
|
|
||||||
|
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
|
||||||
|
|
||||||
|
sensor->updateAccel();
|
||||||
|
int x = sensor->getAccelX(),
|
||||||
|
y = sensor->getAccelY(),
|
||||||
|
z = sensor->getAccelZ();
|
||||||
|
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
||||||
|
|
||||||
|
sensor->updateGyro();
|
||||||
|
int a = sensor->getGyroX(),
|
||||||
|
b = sensor->getGyroY(),
|
||||||
|
c = sensor->getGyroZ();
|
||||||
|
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
||||||
|
|
||||||
|
int axis, direction;
|
||||||
|
sensor->enableShockDetection(true);
|
||||||
|
for(int i=0; i<300; i++) {
|
||||||
|
if (sensor->isShockDetected()) {
|
||||||
|
sensor->getNextShock();
|
||||||
|
axis = sensor->getAxis();
|
||||||
|
direction = sensor->getDirection();
|
||||||
|
printf("shock data is: %d, %d\n", axis, direction);
|
||||||
|
}
|
||||||
|
usleep(10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
sensor->updateMotion();
|
||||||
|
int m = sensor->getAccelX(),
|
||||||
|
n = sensor->getAccelY(),
|
||||||
|
o = sensor->getAccelZ(),
|
||||||
|
p = sensor->getGyroX(),
|
||||||
|
q = sensor->getGyroY(),
|
||||||
|
r = sensor->getGyroZ();
|
||||||
|
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
82
examples/c++/cwlsxxa.cxx
Normal file
82
examples/c++/cwlsxxa.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "cwlsxxa.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
// humidity and A2 for temperature
|
||||||
|
upm::CWLSXXA *sensor = new upm::CWLSXXA(0, 1, 2);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Temperature: " << sensor->getTemperature()
|
||||||
|
<< " C / " << sensor->getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Humidity: " << sensor->getHumidity()
|
||||||
|
<< " %" << endl;
|
||||||
|
|
||||||
|
cout << "CO2: " << sensor->getCO2()
|
||||||
|
<< " ppm" << endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/ds1808lc.cxx
Normal file
51
examples/c++/ds1808lc.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "ds1808lc.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
if (lightController->isPowered())
|
||||||
|
{
|
||||||
|
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Light is not powered." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
upm::ILightController* lightController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete lightController;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
112
examples/c++/e50hx.cxx
Normal file
112
examples/c++/e50hx.cxx
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "e50hx.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// You will need to edit this example to conform to your site and your
|
||||||
|
// devices, specifically the Device Object Instance ID passed to the
|
||||||
|
// constructor, and the arguments to initMaster() that are
|
||||||
|
// appropriate for your BACnet network.
|
||||||
|
|
||||||
|
string defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = string(argv[1]);
|
||||||
|
|
||||||
|
cout << "Using device " << defaultDev << endl;
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an E50HX object for an E50HX device that has 1075425
|
||||||
|
// as it's unique Device Object Instance ID. NOTE: You will
|
||||||
|
// certainly want to change this to the correct value for your
|
||||||
|
// device(s).
|
||||||
|
E50HX *sensor = new E50HX(1075425);
|
||||||
|
|
||||||
|
// Initialize our BACnet master, if it has not already been
|
||||||
|
// initialized, with the device and baudrate, choosing 1000001 as
|
||||||
|
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||||
|
// using default values for maxMaster and maxInfoFrames
|
||||||
|
sensor->initMaster(defaultDev, 38400, 1000001, 2);
|
||||||
|
|
||||||
|
// Uncomment to enable debugging output
|
||||||
|
// sensor->setDebug(true);
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
cout << "Device Description: " << sensor->getDescription() << endl;
|
||||||
|
cout << "Device Location: " << sensor->getLocation() << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
// update and print a few values every 5 seconds
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
cout << "System Voltage: "
|
||||||
|
<< sensor->getAnalogValue(E50HX::AV_System_Voltage)
|
||||||
|
<< " " << sensor->getAnalogValueUnits(E50HX::AV_System_Voltage)
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "System Type: "
|
||||||
|
<< sensor->getAnalogValue(E50HX::AV_System_Type)
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Energy Consumption: " << sensor->getAnalogInput(E50HX::AI_Energy)
|
||||||
|
<< " " << sensor->getAnalogInputUnits(E50HX::AI_Energy)
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Power Up Counter: "
|
||||||
|
<< sensor->getAnalogInput(E50HX::AI_Power_Up_Count)
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
sleep(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
149
examples/c++/h803x.cxx
Normal file
149
examples/c++/h803x.cxx
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "h803x.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
string defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = string(argv[1]);
|
||||||
|
|
||||||
|
cout << "Using device " << defaultDev << endl;
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
// default comm parameters (9600, 8, N, 2)
|
||||||
|
upm::H803X *sensor = new upm::H803X(defaultDev, 1);
|
||||||
|
|
||||||
|
// output the Slave ID string
|
||||||
|
cout << "Slave ID: " << sensor->getSlaveID() << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
// H8035 / H8036
|
||||||
|
cout << "Consumption (kWh): " << sensor->getConsumption() << endl;
|
||||||
|
cout << "Real Power (kW): " << sensor->getRealPower() << endl;
|
||||||
|
|
||||||
|
if (sensor->isH8036())
|
||||||
|
{
|
||||||
|
// The H8036 has much more data available...
|
||||||
|
|
||||||
|
cout << "Reactive Power (kVAR): " << sensor->getReactivePower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Apparent Power (kVA): " << sensor->getApparentPower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Power Factor: " << sensor->getPowerFactor()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Line to Line: " << sensor->getVoltsLineToLine()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Line to Neutral: " << sensor->getVoltsLineToNeutral()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Current: " << sensor->getCurrent()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Real Power Phase A (kW): " << sensor->getRealPowerPhaseA()
|
||||||
|
<< endl;
|
||||||
|
cout << "Real Power Phase B (kW): " << sensor->getRealPowerPhaseB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Real Power Phase C (kW): " << sensor->getRealPowerPhaseC()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Power Factor Phase A: " << sensor->getPowerFactorPhaseA()
|
||||||
|
<< endl;
|
||||||
|
cout << "Power Factor Phase B: " << sensor->getPowerFactorPhaseB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Power Factor Phase C: " << sensor->getPowerFactorPhaseC()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Volts Phase A to B: " << sensor->getVoltsPhaseAToB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase B to C: " << sensor->getVoltsPhaseBToC()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase A to C: " << sensor->getVoltsPhaseAToC()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase A to Neutral: "
|
||||||
|
<< sensor->getVoltsPhaseAToNeutral()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase B to Neutral: "
|
||||||
|
<< sensor->getVoltsPhaseBToNeutral()
|
||||||
|
<< endl;
|
||||||
|
cout << "Volts Phase C to Neutral: "
|
||||||
|
<< sensor->getVoltsPhaseCToNeutral()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Current Phase A: " << sensor->getCurrentPhaseA()
|
||||||
|
<< endl;
|
||||||
|
cout << "Current Phase B: " << sensor->getCurrentPhaseB()
|
||||||
|
<< endl;
|
||||||
|
cout << "Current Phase C: " << sensor->getCurrentPhaseC()
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << "Avg Real Power (kW): " << sensor->getAvgRealPower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Min Real Power (kW): " << sensor->getMinRealPower()
|
||||||
|
<< endl;
|
||||||
|
cout << "Max Real Power (kW): " << sensor->getMaxRealPower()
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/hlg150h.cxx
Normal file
51
examples/c++/hlg150h.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "hlg150h.h"
|
||||||
|
|
||||||
|
#define HLG150H_GPIO_RELAY 21
|
||||||
|
#define HLG150H_GPIO_PWM 22
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
if (lightController->isPowered())
|
||||||
|
{
|
||||||
|
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Light is not powered." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
upm::ILightController* lightController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
delete lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +135,7 @@ int main (int argc, char **argv)
|
|||||||
if (rv > 0)
|
if (rv > 0)
|
||||||
cout << "Received: " << radioBuffer << endl;
|
cout << "Received: " << radioBuffer << endl;
|
||||||
|
|
||||||
if (rv < 0) // some sort of read error occured
|
if (rv < 0) // some sort of read error occurred
|
||||||
{
|
{
|
||||||
cerr << "Port read error." << endl;
|
cerr << "Port read error." << endl;
|
||||||
break;
|
break;
|
||||||
|
82
examples/c++/humidity-sensor.cxx
Normal file
82
examples/c++/humidity-sensor.cxx
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si7005.h"
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ILightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::IHumiditySensor* getHumiditySensor()
|
||||||
|
{
|
||||||
|
upm::IHumiditySensor* humiditySensor = NULL;
|
||||||
|
try {
|
||||||
|
humiditySensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return humiditySensor ;
|
||||||
|
} catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr <<"BME280: "<<e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
humiditySensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
return humiditySensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return humiditySensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::IHumiditySensor* humiditySensor = getHumiditySensor();
|
||||||
|
if (humiditySensor == NULL) {
|
||||||
|
std::cout << "Humidity sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Humidity sensor " << humiditySensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
int value = humiditySensor->getHumidityRelative();
|
||||||
|
std::cout << "Humidity = " << value << "%" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete humiditySensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
98
examples/c++/light-controller.cxx
Normal file
98
examples/c++/light-controller.cxx
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "lp8860.h"
|
||||||
|
#include "ds1808lc.h"
|
||||||
|
#include "hlg150h.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define GPIO_SI7005_CS 20 // Edison GP12
|
||||||
|
#define HLG150H_GPIO_RELAY 21
|
||||||
|
#define HLG150H_GPIO_PWM 22
|
||||||
|
#define LP8860_GPIO_PWR 45 // Edison GP45
|
||||||
|
#define DS1808_GPIO_PWR 15 // Edison GP165
|
||||||
|
#define DS1808_GPIO_EDISON_LIVE 36 // Edison GP14
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightController to determine
|
||||||
|
// which controller is present and return its name.
|
||||||
|
// ILightController is then used to get readings from sensor
|
||||||
|
|
||||||
|
upm::ILightController* getLightController()
|
||||||
|
{
|
||||||
|
upm::ILightController* lightController = NULL;
|
||||||
|
try {
|
||||||
|
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "LP8860: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightController = new upm::DS1808LC(DS1808_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "DS1808LC: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightController = new upm::HLG150H(HLG150H_GPIO_RELAY, HLG150H_GPIO_PWM);
|
||||||
|
return lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "HLG150H: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return lightController;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
if (lightController->isPowered())
|
||||||
|
{
|
||||||
|
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Light is not powered." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
// MraaUtils::setGpio(GPIO_SI7005_CS, 1);
|
||||||
|
|
||||||
|
upm::ILightController *lightController = getLightController();
|
||||||
|
if (lightController != NULL)
|
||||||
|
{
|
||||||
|
std::cout << "Detected light controller " << lightController->getModuleName() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Error. Unsupported platform." << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete lightController;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
78
examples/c++/light-sensor.cxx
Normal file
78
examples/c++/light-sensor.cxx
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "max44009.h"
|
||||||
|
#include "si1132.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ILightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::ILightSensor* getLightSensor()
|
||||||
|
{
|
||||||
|
upm::ILightSensor* lightSensor = NULL;
|
||||||
|
try {
|
||||||
|
lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI1132: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
||||||
|
return lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "MAX44009: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return lightSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::ILightSensor* lightSensor = getLightSensor();
|
||||||
|
if (lightSensor == NULL) {
|
||||||
|
std::cout << "Light sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Light sensor " << lightSensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
float value = lightSensor->getVisibleLux();
|
||||||
|
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete lightSensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
52
examples/c++/lp8860.cxx
Normal file
52
examples/c++/lp8860.cxx
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include "lp8860.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1 // Edison I2C-1
|
||||||
|
#define LP8860_GPIO_PWR 45 // Edison GP45
|
||||||
|
|
||||||
|
|
||||||
|
void printState(upm::ILightController *lightController)
|
||||||
|
{
|
||||||
|
if (lightController->isPowered())
|
||||||
|
{
|
||||||
|
std::cout << "Light is powered, brightness = " << lightController->getBrightness() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "Light is not powered." << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main( int argc, char **argv )
|
||||||
|
{
|
||||||
|
int status = 0;
|
||||||
|
upm::LP8860* lightController;
|
||||||
|
|
||||||
|
try {
|
||||||
|
lightController = new upm::LP8860(LP8860_GPIO_PWR, EDISON_I2C_BUS);
|
||||||
|
std::cout << "Existing state: "; printState(lightController);
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
std::string arg = argv[1];
|
||||||
|
int brightness = ::atoi(argv[1]);
|
||||||
|
if (brightness > 0) {
|
||||||
|
lightController->setPowerOn();
|
||||||
|
lightController->setBrightness(brightness);
|
||||||
|
} else
|
||||||
|
lightController->setPowerOff();
|
||||||
|
}
|
||||||
|
std::cout << "Now: ";printState(lightController);
|
||||||
|
delete lightController;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cout << "Error: " << e.what() << std::endl;
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
46
examples/c++/max44009.cxx
Normal file
46
examples/c++/max44009.cxx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "max44009.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::MAX44009* lightSensor = new upm::MAX44009(EDISON_I2C_BUS);
|
||||||
|
while (true) {
|
||||||
|
float value = lightSensor->getVisibleLux();
|
||||||
|
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
81
examples/c++/pressure-sensor.cxx
Normal file
81
examples/c++/pressure-sensor.cxx
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "bmp180.h"
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ILightSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ILightSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::IPressureSensor* getPressureSensor()
|
||||||
|
{
|
||||||
|
upm::IPressureSensor* pressureSensor = NULL;
|
||||||
|
try {
|
||||||
|
pressureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return pressureSensor ;
|
||||||
|
} catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr <<"BME280: "<<e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
pressureSensor = new upm::BMP180(EDISON_I2C_BUS);
|
||||||
|
return pressureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BMP180: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return pressureSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::IPressureSensor* pressureSensor = getPressureSensor();
|
||||||
|
if (pressureSensor == NULL) {
|
||||||
|
std::cout << "Pressure sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Pressure sensor " << pressureSensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
int value = pressureSensor->getPressurePa();
|
||||||
|
std::cout << "Pressure = " << value << " Pa" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete pressureSensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
46
examples/c++/si1132.cxx
Normal file
46
examples/c++/si1132.cxx
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si1132.h"
|
||||||
|
|
||||||
|
#define FT4222_I2C_BUS 1
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::SI1132* lightSensor = new upm::SI1132(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
while (true) {
|
||||||
|
float value = lightSensor->getVisibleLux();
|
||||||
|
std::cout << "Light level = " << value << " lux" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete lightSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
51
examples/c++/si7005.cxx
Normal file
51
examples/c++/si7005.cxx
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si7005.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
upm::SI7005* sensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
while (true) {
|
||||||
|
int temperature = sensor->getTemperatureCelcius();
|
||||||
|
int humidity = sensor->getHumidityRelative();
|
||||||
|
std::cout << "Temperature = " << temperature << "C" << std::endl;
|
||||||
|
std::cout << "Humidity = " << humidity << "%" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete sensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
75
examples/c++/smartdrive.cxx
Normal file
75
examples/c++/smartdrive.cxx
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Author: Oussema Harbi <oussema.elharbi@gmail.com>
|
||||||
|
* Copyright (c) <2016> <Oussema Harbi>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "smartdrive.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
upm::SmartDrive *drive = NULL;
|
||||||
|
|
||||||
|
void
|
||||||
|
sig_handler(int signo)
|
||||||
|
{
|
||||||
|
printf("got signal\n");
|
||||||
|
if (signo == SIGINT) {
|
||||||
|
printf("exiting application\n");
|
||||||
|
if (drive != NULL)
|
||||||
|
delete drive;
|
||||||
|
exit (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
float voltage = 0;
|
||||||
|
|
||||||
|
std::cout << "SmartDrive demo is starting. Please make sure drive is connected to board" << std::endl;
|
||||||
|
sleep(2); //Wait for 2 seconds in case you want to fix your h/w setup
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a SmartDrive connected to /dev/i2c-0 bus, using DefaultAddress
|
||||||
|
drive = new upm::SmartDrive(0);
|
||||||
|
|
||||||
|
std::cout << "Battery Voltage before motor run : " << drive->GetBattVoltage() << std::endl;
|
||||||
|
//Set motor M1 to run for 120 seconds, with speed of 15RPM, waith for it to finish and then Brake It
|
||||||
|
drive->Run_Seconds(SmartDrive_Motor_ID_1, SmartDrive_Dir_Forward, 15, 120, true, SmartDrive_Action_Brake);
|
||||||
|
std::cout << "Battery Voltage after motor run : " << drive->GetBattVoltage() << std::endl;
|
||||||
|
//Rotate motor M2 2270 degrees, in reverse sense, with speed of 10RPM, return immediately from function call
|
||||||
|
drive->Run_Degrees(SmartDrive_Motor_ID_2, SmartDrive_Dir_Reverse, 10, 2270, false, SmartDrive_Action_Float);
|
||||||
|
//While motor is running, Display its status
|
||||||
|
drive->PrintMotorStatus(SmartDrive_Motor_ID_2);
|
||||||
|
sleep(2); //Sleep for 2 seconds
|
||||||
|
//Stop motor M2 and then finish program
|
||||||
|
drive->StopMotor(SmartDrive_Motor_ID_2, SmartDrive_Action_BrakeHold);
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
std::cout << "Demo complete. GoodBye" << std::endl;
|
||||||
|
|
||||||
|
delete drive;
|
||||||
|
drive = NULL;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -29,7 +29,7 @@
|
|||||||
#include "ssd1306.h"
|
#include "ssd1306.h"
|
||||||
|
|
||||||
#define DEVICE_ADDRESS 0x3C
|
#define DEVICE_ADDRESS 0x3C
|
||||||
#define BUS_NUMBER 0x6
|
#define BUS_NUMBER 0x0
|
||||||
|
|
||||||
static uint8_t intel_logo[] = {
|
static uint8_t intel_logo[] = {
|
||||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
61
examples/c++/ssd1351.cxx
Normal file
61
examples/c++/ssd1351.cxx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "mraa.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "ssd1351.h"
|
||||||
|
|
||||||
|
#define BLACK 0x0000
|
||||||
|
#define WHITE 0xFFFF
|
||||||
|
#define INTEL_BLUE 0x0BF8
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
// Define colors (16-bit RGB on 5/6/5 bits)
|
||||||
|
int colors[] = {0x0000, 0x000F, 0x03E0, 0x03EF,
|
||||||
|
0x7800, 0x780F, 0x7BE0, 0xC618,
|
||||||
|
0x7BEF, 0x001F, 0x07E0, 0x07FF,
|
||||||
|
0xF800, 0xF81F, 0xFFE0, 0xFFFF};
|
||||||
|
//! [Interesting]
|
||||||
|
// Initialize display with pins
|
||||||
|
// oc = 0, dc = 1, r = 2, si = 11, cl = 13
|
||||||
|
upm::SSD1351* display = new upm::SSD1351(0, 1, 2);
|
||||||
|
|
||||||
|
// Test lines pixel by pixel
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT; i++) {
|
||||||
|
for(int j = 0; j < SSD1351WIDTH; j++) {
|
||||||
|
display->drawPixel(i, j, colors[i/8]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test rectangles
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
|
||||||
|
for (int j = 0; j < SSD1351WIDTH/32; j++) {
|
||||||
|
display->fillRect(i * 32, j * 32, 32, 32, colors[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test circles
|
||||||
|
display->fillScreen(0x2104);
|
||||||
|
for(int i = 0; i < SSD1351HEIGHT/32; i++) {
|
||||||
|
for (int j = 0; j < SSD1351WIDTH/32; j++) {
|
||||||
|
display->drawCircle(i * 32 + 15, j * 32 + 15, 15, colors[i * 4 + j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display->refresh();
|
||||||
|
sleep(5);
|
||||||
|
|
||||||
|
// Test Text
|
||||||
|
display->fillScreen(INTEL_BLUE);
|
||||||
|
display->setTextColor(WHITE, INTEL_BLUE);
|
||||||
|
display->setTextSize(4);
|
||||||
|
display->setCursor(7, 30);
|
||||||
|
display->print("Intel");
|
||||||
|
display->setCursor(5, 70);
|
||||||
|
display->print("IoTDK");
|
||||||
|
display->refresh();
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
48
examples/c++/t6713.cxx
Normal file
48
examples/c++/t6713.cxx
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "t6713.h"
|
||||||
|
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
upm::T6713* cO2Sensor = new upm::T6713(mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
while (true) {
|
||||||
|
uint16_t value = cO2Sensor->getPpm();
|
||||||
|
std::cout << "CO2 level = " << value << " ppm" << std::endl;
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete cO2Sensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
84
examples/c++/teams.cxx
Normal file
84
examples/c++/teams.cxx
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "teams.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
// interface)
|
||||||
|
upm::TEAMS *sensor = new upm::TEAMS(0, 165.0);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
// is the sensor connected? (current >= 4ma)
|
||||||
|
cout << "Is Connected: " << sensor->isConnected() << endl;
|
||||||
|
|
||||||
|
// print computed current on the loop. This includes the offset,
|
||||||
|
// if one was set by setOffsetMilliamps().
|
||||||
|
cout << "Milliamps: " << sensor->getRawMilliamps() << endl;
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Temperature: " << sensor->getTemperature()
|
||||||
|
<< " C / " << sensor->getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
90
examples/c++/temperature-sensor.cxx
Normal file
90
examples/c++/temperature-sensor.cxx
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2015 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include "si7005.h"
|
||||||
|
#include "bmp180.h"
|
||||||
|
#include "bme280.h"
|
||||||
|
|
||||||
|
#define EDISON_I2C_BUS 1
|
||||||
|
#define FT4222_I2C_BUS 0
|
||||||
|
|
||||||
|
#define EDISON_GPIO_SI7005_CS 20
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
// Simple example of using ITemperatureSensor to determine
|
||||||
|
// which sensor is present and return its name.
|
||||||
|
// ITemperatureSensor is then used to get readings from sensor
|
||||||
|
|
||||||
|
|
||||||
|
upm::ITemperatureSensor* getTemperatureSensor()
|
||||||
|
{
|
||||||
|
upm::ITemperatureSensor* temperatureSensor = NULL;
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::BME280 (mraa_get_sub_platform_id(FT4222_I2C_BUS));
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr <<"BME280: "<<e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::SI7005(EDISON_I2C_BUS, EDISON_GPIO_SI7005_CS);
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "SI7005: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
temperatureSensor = new upm::BMP180(EDISON_I2C_BUS);
|
||||||
|
return temperatureSensor;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << "BMP180: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
return temperatureSensor;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main ()
|
||||||
|
{
|
||||||
|
upm::ITemperatureSensor* temperatureSensor = getTemperatureSensor();
|
||||||
|
if (temperatureSensor == NULL) {
|
||||||
|
std::cout << "Temperature sensor not detected" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
std::cout << "Temperature sensor " << temperatureSensor->getModuleName() << " detected" << std::endl;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
int value = temperatureSensor->getTemperatureCelcius();
|
||||||
|
std::cout << "Temperature = " << value << "C" << std::endl;
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
delete temperatureSensor;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! [Interesting]
|
91
examples/c++/tex00.cxx
Normal file
91
examples/c++/tex00.cxx
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#include "tex00.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool shouldRun = true;
|
||||||
|
|
||||||
|
void sig_handler(int signo)
|
||||||
|
{
|
||||||
|
if (signo == SIGINT)
|
||||||
|
shouldRun = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_handler);
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
// this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
// (10k type 2) thermistor.
|
||||||
|
upm::TEX00 *sensor = new upm::TEX00(0, 10000,
|
||||||
|
upm::TEX00::STYPE_THERMISTOR_TED);
|
||||||
|
|
||||||
|
cout << "Minimum temperature: " << sensor->getTemperatureRangeMin()
|
||||||
|
<< " C" << endl;
|
||||||
|
cout << "Maximum temperature: " << sensor->getTemperatureRangeMax()
|
||||||
|
<< " C" << endl;
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
while (shouldRun)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor->update();
|
||||||
|
|
||||||
|
if (sensor->isOutOfRange())
|
||||||
|
{
|
||||||
|
cout << "Temperature out of range" << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we show both C and F for temperature
|
||||||
|
cout << "Temperature: " << sensor->getTemperature()
|
||||||
|
<< " C / " << sensor->getTemperature(true) << " F"
|
||||||
|
<< endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << endl;
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -77,7 +77,7 @@ int main (int argc, char **argv)
|
|||||||
if (rv > 0)
|
if (rv > 0)
|
||||||
write(1, nmeaBuffer, rv);
|
write(1, nmeaBuffer, rv);
|
||||||
|
|
||||||
if (rv < 0) // some sort of read error occured
|
if (rv < 0) // some sort of read error occurred
|
||||||
{
|
{
|
||||||
cerr << "Port read error." << endl;
|
cerr << "Port read error." << endl;
|
||||||
break;
|
break;
|
||||||
|
70
examples/c++/vcap.cxx
Normal file
70
examples/c++/vcap.cxx
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "vcap.hpp"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
string defaultDev = "/dev/video0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (argc > 1)
|
||||||
|
defaultDev = string(argv[1]);
|
||||||
|
|
||||||
|
cout << "Using device " << defaultDev << endl;
|
||||||
|
cout << "Initializing..." << endl;
|
||||||
|
|
||||||
|
// Instantiate an VCAP instance, using the specified video device
|
||||||
|
upm::VCAP *sensor = new upm::VCAP(defaultDev);
|
||||||
|
|
||||||
|
// enable some debug/verbose output
|
||||||
|
sensor->setDebug(true);
|
||||||
|
|
||||||
|
// This is just a hint. The kernel can change this to a lower
|
||||||
|
// resolution that the hardware supports. Use getWidth() and
|
||||||
|
// getHeight() methods to see what the kernel actually chose if you
|
||||||
|
// care.
|
||||||
|
sensor->setResolution(1920, 1080);
|
||||||
|
|
||||||
|
// capture an image
|
||||||
|
sensor->captureImage();
|
||||||
|
|
||||||
|
// convert and save it as a jpeg
|
||||||
|
sensor->saveImage("video-img1.jpg");
|
||||||
|
|
||||||
|
cout << "Exiting..." << endl;
|
||||||
|
|
||||||
|
delete sensor;
|
||||||
|
|
||||||
|
//! [Interesting]
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
66
examples/java/AM2315Example.java
Normal file
66
examples/java/AM2315Example.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_am2315.AM2315;
|
||||||
|
|
||||||
|
public class AM2315Example {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_am2315");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
float humidity = 0;
|
||||||
|
float temperature = 0;
|
||||||
|
|
||||||
|
// Instantiate the sensor
|
||||||
|
AM2315 sensor = new AM2315(0, upm_am2315.javaupm_am2315Constants.AM2315_I2C_ADDRESS);
|
||||||
|
sensor.testSensor();
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
// retrieving the humidity and temperature values
|
||||||
|
humidity = sensor.getHumidity();
|
||||||
|
temperature = sensor.getTemperature();
|
||||||
|
|
||||||
|
System.out.println("Temperature : "+temperature+" Humidity: "+humidity);
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
44
examples/java/APA102Sample.java
Normal file
44
examples/java/APA102Sample.java
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class APA102Sample {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
// ! [Interesting]
|
||||||
|
// Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
|
upm_apa102.APA102 ledStrip =
|
||||||
|
new upm_apa102.APA102(30, (short)0, false, (byte)-1);
|
||||||
|
|
||||||
|
System.out.println("Set all LEDs to blue");
|
||||||
|
ledStrip.setAllLeds((short)31, (short)0, (short)0, (short)255);
|
||||||
|
|
||||||
|
System.out.println("Set LEDs between 10 and 20 to green");
|
||||||
|
ledStrip.setLeds(10, 20, (short)31, (short)0, (short)255, (short)0);
|
||||||
|
|
||||||
|
System.out.println("Set a single LED to red at index 15");
|
||||||
|
ledStrip.setLed(15, (short)31, (short)255, (short)0, (short)0);
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
50
examples/java/Ad8232Example.java
Normal file
50
examples/java/Ad8232Example.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_ad8232.AD8232;
|
||||||
|
|
||||||
|
public class Ad8232Example {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Instantiate a Ad8232 sensor on digital pins 10 (LO+), 11 (LO-)
|
||||||
|
// and an analog pin, 0 (OUTPUT)
|
||||||
|
AD8232 ad8232 = new AD8232(10, 11, 0);
|
||||||
|
while(true){
|
||||||
|
// Output the raw numbers from the ADC, for plotting elsewhere.
|
||||||
|
// A return of 0 indicates a Lead Off (LO) condition.
|
||||||
|
// In theory, this data could be fed to software like Processing
|
||||||
|
// (https://www.processing.org/) to plot the data just like an
|
||||||
|
// EKG you would see in a hospital.
|
||||||
|
System.out.println(ad8232.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following error has occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -38,7 +38,7 @@ public class Apds9002 {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
System.out.println("The following exception occured: "+e.getMessage());
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
78
examples/java/BMI160_Example.java
Normal file
78
examples/java/BMI160_Example.java
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_bmi160.BMI160;
|
||||||
|
|
||||||
|
public class BMI160_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
BMI160 sensor = new BMI160();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
float dataA[] = sensor.getAccelerometer();
|
||||||
|
|
||||||
|
System.out.println("Accelerometer: "
|
||||||
|
+ "AX: "
|
||||||
|
+ dataA[0]
|
||||||
|
+ " AY: "
|
||||||
|
+ dataA[1]
|
||||||
|
+ " AZ: "
|
||||||
|
+ dataA[2]);
|
||||||
|
|
||||||
|
float dataG[] = sensor.getGyroscope();
|
||||||
|
|
||||||
|
System.out.println("Gryoscope: "
|
||||||
|
+ "GX: "
|
||||||
|
+ dataG[0]
|
||||||
|
+ " GY: "
|
||||||
|
+ dataG[1]
|
||||||
|
+ " GZ: "
|
||||||
|
+ dataG[2]);
|
||||||
|
|
||||||
|
float dataM[] = sensor.getMagnetometer();
|
||||||
|
|
||||||
|
System.out.println("Magnetometer: "
|
||||||
|
+ "MX: "
|
||||||
|
+ dataM[0]
|
||||||
|
+ " MY: "
|
||||||
|
+ dataM[1]
|
||||||
|
+ " MZ: "
|
||||||
|
+ dataM[2]);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(500);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -6,13 +6,15 @@ macro(add_example example_name jar_name)
|
|||||||
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_name}/upm_${jar_name}.jar")
|
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_name}/upm_${jar_name}.jar")
|
||||||
|
|
||||||
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
||||||
|
add_dependencies(${example_name} javaupm_${jar_name})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(add_example_with_path example_name jar_path)
|
macro(add_example_with_path example_name jar_path jar_name)
|
||||||
set(example_src "${example_name}.java")
|
set(example_src "${example_name}.java")
|
||||||
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_path}")
|
set(example_jar "${CMAKE_CURRENT_BINARY_DIR}/../../src/${jar_path}/upm_${jar_name}.jar")
|
||||||
|
|
||||||
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
add_jar(${example_name} SOURCES ${example_src} INCLUDE_JARS ${example_jar})
|
||||||
|
add_dependencies(${example_name} javaupm_${jar_name})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
add_example(A110X_intrSample a110x)
|
add_example(A110X_intrSample a110x)
|
||||||
@ -101,12 +103,29 @@ add_example(WaterLevelSensor waterlevel)
|
|||||||
add_example(WT5001Sample wt5001)
|
add_example(WT5001Sample wt5001)
|
||||||
add_example(YG1006Sample yg1006)
|
add_example(YG1006Sample yg1006)
|
||||||
add_example(ZFM20Sample zfm20)
|
add_example(ZFM20Sample zfm20)
|
||||||
|
add_example(Ad8232Example ad8232)
|
||||||
|
add_example(Gp2y0aExample gp2y0a)
|
||||||
|
add_example(Th02Example th02)
|
||||||
|
add_example(FlexSensorExample flex)
|
||||||
|
add_example(CWLSXXA_Example cwlsxxa)
|
||||||
|
add_example(TEAMS_Example teams)
|
||||||
|
add_example(APA102Sample apa102)
|
||||||
|
add_example(TEX00_Example tex00)
|
||||||
|
add_example(BMI160_Example bmi160)
|
||||||
|
add_example(Tsl2561 tsl2561)
|
||||||
|
add_example(AM2315Example am2315)
|
||||||
|
if (MODBUS_FOUND)
|
||||||
|
add_example(H803X_Example h803x)
|
||||||
|
endif()
|
||||||
|
if (BACNET_FOUND)
|
||||||
|
add_example(E50HX_Example e50hx)
|
||||||
|
endif()
|
||||||
|
add_example(VCAP_Example vcap)
|
||||||
|
|
||||||
|
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||||
add_example_with_path(Jhd1313m1_lcdSample lcd/upm_i2clcd.jar)
|
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||||
add_example_with_path(Jhd1313m1Sample lcd/upm_i2clcd.jar)
|
add_example_with_path(Lcm1602_i2cSample lcd i2clcd)
|
||||||
add_example_with_path(Lcm1602_i2cSample lcd/upm_i2clcd.jar)
|
add_example_with_path(Lcm1602_parallelSample lcd i2clcd)
|
||||||
add_example_with_path(Lcm1602_parallelSample lcd/upm_i2clcd.jar)
|
add_example_with_path(SSD1308_oledSample lcd i2clcd)
|
||||||
add_example_with_path(SSD1308_oledSample lcd/upm_i2clcd.jar)
|
add_example_with_path(SSD1327_oledSample lcd i2clcd)
|
||||||
add_example_with_path(SSD1327_oledSample lcd/upm_i2clcd.jar)
|
|
||||||
|
|
||||||
|
62
examples/java/CWLSXXA_Example.java
Normal file
62
examples/java/CWLSXXA_Example.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_cwlsxxa.CWLSXXA;
|
||||||
|
|
||||||
|
public class CWLSXXA_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
// humidity and A2 for temperature
|
||||||
|
CWLSXXA sensor = new CWLSXXA(0, 1, 2);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println("Humidity: "
|
||||||
|
+ sensor.getHumidity()
|
||||||
|
+ " %");
|
||||||
|
|
||||||
|
System.out.println("CO2: "
|
||||||
|
+ sensor.getCO2()
|
||||||
|
+ " ppm");
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
90
examples/java/E50HX_Example.java
Normal file
90
examples/java/E50HX_Example.java
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_e50hx.E50HX;
|
||||||
|
|
||||||
|
public class E50HX_Example
|
||||||
|
{
|
||||||
|
private static String defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
|
||||||
|
// You will need to edit this example to conform to your site
|
||||||
|
// and your devices, specifically the Device Object Instance
|
||||||
|
// ID passed to the constructor, and the arguments to
|
||||||
|
// initMaster() that are appropriate for your BACnet network.
|
||||||
|
|
||||||
|
if (args.length > 0)
|
||||||
|
defaultDev = args[0];
|
||||||
|
System.out.println("Using device " + defaultDev);
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an E50HX object for an E50HX device that has
|
||||||
|
// 1075425 as it's unique Device Object Instance ID. NOTE:
|
||||||
|
// You will certainly want to change this to the correct value
|
||||||
|
// for your device(s).
|
||||||
|
E50HX sensor = new E50HX(1075425);
|
||||||
|
|
||||||
|
// Initialize our BACnet master, if it has not already been
|
||||||
|
// initialized, with the device and baudrate, choosing 1000001 as
|
||||||
|
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||||
|
// using default values for maxMaster and maxInfoFrames
|
||||||
|
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||||
|
|
||||||
|
// Uncomment to enable debugging output
|
||||||
|
// sensor.setDebug(true);
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
System.out.println("Device Description: " + sensor.getDescription());
|
||||||
|
System.out.println("Device Location: " + sensor.getLocation());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
// update and print a few values every 5 seconds
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
System.out.println("System Voltage: "
|
||||||
|
+ sensor.getAnalogValue(E50HX.ANALOG_VALUES_T.AV_System_Voltage)
|
||||||
|
+ " "
|
||||||
|
+ sensor.getAnalogValueUnits(E50HX.ANALOG_VALUES_T.AV_System_Voltage));
|
||||||
|
|
||||||
|
System.out.println("System Type: "
|
||||||
|
+ sensor.getAnalogValue(E50HX.ANALOG_VALUES_T.AV_System_Type));
|
||||||
|
|
||||||
|
System.out.println("Energy Consumption: "
|
||||||
|
+ sensor.getAnalogInput(E50HX.ANALOG_INPUTS_T.AI_Energy)
|
||||||
|
+ " "
|
||||||
|
+ sensor.getAnalogInputUnits(E50HX.ANALOG_INPUTS_T.AI_Energy));
|
||||||
|
|
||||||
|
System.out.println("Power Up Counter: "
|
||||||
|
+ sensor.getAnalogInput(E50HX.ANALOG_INPUTS_T.AI_Power_Up_Count));
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
41
examples/java/FlexSensorExample.java
Normal file
41
examples/java/FlexSensorExample.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import upm_flex.Flex;
|
||||||
|
|
||||||
|
public class FlexSensorExample {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_flex");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// The was tested with a Spectra Symbol flex sensor.
|
||||||
|
// We attached a 22K resistor to a breadboard,
|
||||||
|
// with 1 end attached to GND and the other connected to
|
||||||
|
// both the flex sensor and A0.
|
||||||
|
// The flex sensor was connected on 1 pin to the 22K resistor and A0
|
||||||
|
// and on the other pin to 5V.
|
||||||
|
|
||||||
|
// Instantiate a Flex sensor on analog pin A0
|
||||||
|
Flex flex = new Flex(0);
|
||||||
|
while(true){
|
||||||
|
System.out.println("Flex Sensor value is: "+flex.value());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
68
examples/java/Gp2y0aExample.java
Normal file
68
examples/java/Gp2y0aExample.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_gp2y0a.GP2Y0A;
|
||||||
|
|
||||||
|
public class Gp2y0aExample {
|
||||||
|
|
||||||
|
public static final float GP2Y0A_AREF = 5;
|
||||||
|
public static final short SAMPLES_PER_QUERY = 20;
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_gp2y0a");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
// Note, for the Grove 80cm version of this sensor, due to the way
|
||||||
|
// it is wired, you need to plug this into the A0 port, where it
|
||||||
|
// will use the available A1 pin for data.
|
||||||
|
|
||||||
|
// Instantiate a GP2Y0A on analog pin A1
|
||||||
|
GP2Y0A gp2y0a = new GP2Y0A(1);
|
||||||
|
|
||||||
|
// The higher the voltage (closer to AREF) the closer the object is. NOTE:
|
||||||
|
// the measured voltage will probably not exceed 3.3 volts.
|
||||||
|
// Every second, print the averaged voltage value (averaged over 20 samples).
|
||||||
|
while(true){
|
||||||
|
System.out.println("AREF: " + GP2Y0A_AREF + "\t, Voltage Value (Higher means Closer): "+ gp2y0a.value(GP2Y0A_AREF, SAMPLES_PER_QUERY));
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -39,7 +39,7 @@ public class GroveEmg {
|
|||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
System.out.println("The following exception occured: "+e.getMessage());
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class GroveGsr {
|
|||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
System.out.println("The following exception occured: "+e.getMessage());
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
@ -38,7 +38,7 @@ public class GroveO2Example {
|
|||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
System.out.println("The following exception has occured: "+e.getMessage());
|
System.out.println("The following exception has occurred: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
123
examples/java/H803X_Example.java
Normal file
123
examples/java/H803X_Example.java
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_h803x.H803X;
|
||||||
|
|
||||||
|
public class H803X_Example
|
||||||
|
{
|
||||||
|
private static String defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
if (args.length > 0)
|
||||||
|
defaultDev = args[0];
|
||||||
|
System.out.println("Using device " + defaultDev);
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
// default comm parameters (9600, 8, N, 2)
|
||||||
|
H803X sensor = new H803X(defaultDev, 1);
|
||||||
|
|
||||||
|
// output the Slave ID (manufacturer, model, serno)
|
||||||
|
System.out.println("Slave ID: " + sensor.getSlaveID());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// H8035 / H8036
|
||||||
|
System.out.println("Consumption (kWh): "
|
||||||
|
+ sensor.getConsumption());
|
||||||
|
System.out.println("Real Power (kW): "
|
||||||
|
+ sensor.getRealPower());
|
||||||
|
|
||||||
|
if (sensor.isH8036())
|
||||||
|
{
|
||||||
|
// The H8036 has much more data available...
|
||||||
|
|
||||||
|
System.out.println("Reactive Power (kVAR): "
|
||||||
|
+ sensor.getReactivePower());
|
||||||
|
System.out.println("Apparent Power (kVA): "
|
||||||
|
+ sensor.getApparentPower());
|
||||||
|
System.out.println("Power Factor: "
|
||||||
|
+ sensor.getPowerFactor());
|
||||||
|
System.out.println("Volts Line to Line: "
|
||||||
|
+ sensor.getVoltsLineToLine());
|
||||||
|
System.out.println("Volts Line to Neutral: "
|
||||||
|
+ sensor.getVoltsLineToNeutral());
|
||||||
|
|
||||||
|
System.out.println("Current: " + sensor.getCurrent());
|
||||||
|
|
||||||
|
System.out.println("Real Power Phase A (kW): "
|
||||||
|
+ sensor.getRealPowerPhaseA());
|
||||||
|
System.out.println("Real Power Phase B (kW): "
|
||||||
|
+ sensor.getRealPowerPhaseB());
|
||||||
|
System.out.println("Real Power Phase C (kW): "
|
||||||
|
+ sensor.getRealPowerPhaseC());
|
||||||
|
|
||||||
|
System.out.println("Power Factor Phase A: "
|
||||||
|
+ sensor.getPowerFactorPhaseA());
|
||||||
|
System.out.println("Power Factor Phase B: "
|
||||||
|
+ sensor.getPowerFactorPhaseB());
|
||||||
|
System.out.println("Power Factor Phase C: "
|
||||||
|
+ sensor.getPowerFactorPhaseC());
|
||||||
|
|
||||||
|
System.out.println("Volts Phase A to B: "
|
||||||
|
+ sensor.getVoltsPhaseAToB());
|
||||||
|
System.out.println("Volts Phase B to C: "
|
||||||
|
+ sensor.getVoltsPhaseBToC());
|
||||||
|
System.out.println("Volts Phase A to C: "
|
||||||
|
+ sensor.getVoltsPhaseAToC());
|
||||||
|
System.out.println("Volts Phase A to Neutral: "
|
||||||
|
+ sensor.getVoltsPhaseAToNeutral());
|
||||||
|
System.out.println("Volts Phase B to Neutral: "
|
||||||
|
+ sensor.getVoltsPhaseBToNeutral());
|
||||||
|
System.out.println("Volts Phase C to Neutral: "
|
||||||
|
+ sensor.getVoltsPhaseCToNeutral());
|
||||||
|
|
||||||
|
System.out.println("Current Phase A: "
|
||||||
|
+ sensor.getCurrentPhaseA());
|
||||||
|
System.out.println("Current Phase B: "
|
||||||
|
+ sensor.getCurrentPhaseB());
|
||||||
|
System.out.println("Current Phase C: "
|
||||||
|
+ sensor.getCurrentPhaseC());
|
||||||
|
|
||||||
|
System.out.println("Avg Real Power (kW): "
|
||||||
|
+ sensor.getAvgRealPower());
|
||||||
|
System.out.println("Min Real Power (kW): "
|
||||||
|
+ sensor.getMinRealPower());
|
||||||
|
System.out.println("Max Real Power (kW): "
|
||||||
|
+ sensor.getMaxRealPower());
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -42,7 +42,7 @@ public class HP20xExample {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
System.out.println("The following exception occured: "+e.getMessage());
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
64
examples/java/TEAMS_Example.java
Normal file
64
examples/java/TEAMS_Example.java
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_teams.TEAMS;
|
||||||
|
|
||||||
|
public class TEAMS_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
// interface)
|
||||||
|
TEAMS sensor = new TEAMS(0, 165.0f);
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// is the sensor connected? (current >= 4ma)
|
||||||
|
System.out.println("Is Connected: " + sensor.isConnected());
|
||||||
|
|
||||||
|
// print computed current on the loop. This includes
|
||||||
|
// the offset, if one was set by setOffsetMilliamps().
|
||||||
|
System.out.println("Milliamps: " + sensor.getRawMilliamps());
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
71
examples/java/TEX00_Example.java
Normal file
71
examples/java/TEX00_Example.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_tex00.TEX00;
|
||||||
|
|
||||||
|
public class TEX00_Example
|
||||||
|
{
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
// this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
// (10k type 2) thermistor.
|
||||||
|
TEX00 sensor = new TEX00(0, 10000.0f,
|
||||||
|
TEX00.SENSOR_TYPES_T.STYPE_THERMISTOR_TED);
|
||||||
|
|
||||||
|
System.out.println("Minimum temperature: "
|
||||||
|
+ sensor.getTemperatureRangeMin());
|
||||||
|
System.out.println("Maximum temperature: "
|
||||||
|
+ sensor.getTemperatureRangeMax());
|
||||||
|
System.out.println();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
if (sensor.isOutOfRange())
|
||||||
|
{
|
||||||
|
System.out.println("Temperature out of range");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we show both C and F for temperature
|
||||||
|
System.out.println("Temperature: "
|
||||||
|
+ sensor.getTemperature()
|
||||||
|
+ " C / "
|
||||||
|
+ sensor.getTemperature(true)
|
||||||
|
+ " F");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
47
examples/java/Th02Example.java
Normal file
47
examples/java/Th02Example.java
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_th02.TH02;
|
||||||
|
|
||||||
|
public class Th02Example {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
float temperature = 0;
|
||||||
|
float humidity = 0;
|
||||||
|
|
||||||
|
TH02 sensor = new TH02();
|
||||||
|
while(true){
|
||||||
|
temperature = sensor.getTemperature();
|
||||||
|
humidity = sensor.getHumidity();
|
||||||
|
System.out.println("Temperature = "+temperature+", Humidity = "+humidity);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception has occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
examples/java/Tsl2561.java
Normal file
61
examples/java/Tsl2561.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Author: Abhishek Malik <abhishek.malik@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
import upm_tsl2561.TSL2561;
|
||||||
|
|
||||||
|
public class Tsl2561 {
|
||||||
|
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_tsl2561");
|
||||||
|
System.loadLibrary("mraajava");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println(
|
||||||
|
"Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
|
||||||
|
e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
//! [Interesting]
|
||||||
|
TSL2561 sensor = null;
|
||||||
|
int loopCount = 100;
|
||||||
|
// Instantiate the sensor object
|
||||||
|
sensor = new TSL2561();
|
||||||
|
|
||||||
|
for (int i=0; i<loopCount; i++){
|
||||||
|
// retrieving and displaying the Lux value
|
||||||
|
System.out.println("Lux: "+sensor.getLux());
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! [Interesting]
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
60
examples/java/VCAP_Example.java
Normal file
60
examples/java/VCAP_Example.java
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import upm_vcap.VCAP;
|
||||||
|
|
||||||
|
public class VCAP_Example
|
||||||
|
{
|
||||||
|
private static String defaultDev = "/dev/video0";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws InterruptedException
|
||||||
|
{
|
||||||
|
// ! [Interesting]
|
||||||
|
if (args.length > 0)
|
||||||
|
defaultDev = args[0];
|
||||||
|
|
||||||
|
System.out.println("Using device " + defaultDev);
|
||||||
|
System.out.println("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an VCAP instance, using the specified video device
|
||||||
|
VCAP sensor = new VCAP(defaultDev);
|
||||||
|
|
||||||
|
// enable some debug/verbose output
|
||||||
|
sensor.setDebug(true);
|
||||||
|
|
||||||
|
// This is just a hint. The kernel can change this to a lower
|
||||||
|
// resolution that the hardware supports. Use getWidth() and
|
||||||
|
// getHeight() methods to see what the kernel actually chose if you
|
||||||
|
// care.
|
||||||
|
sensor.setResolution(1920, 1080);
|
||||||
|
|
||||||
|
// capture an image
|
||||||
|
sensor.captureImage();
|
||||||
|
|
||||||
|
// convert and save it as a jpeg
|
||||||
|
sensor.saveImage("video-img1.jpg");
|
||||||
|
|
||||||
|
// ! [Interesting]
|
||||||
|
}
|
||||||
|
}
|
@ -43,7 +43,7 @@ public class WaterLevelSensor {
|
|||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
System.out.println("The following exception occured: "+e.getMessage());
|
System.out.println("The following exception occurred: "+e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
|
44
examples/javascript/apa102.js
Normal file
44
examples/javascript/apa102.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var lib = require('jsupm_apa102');
|
||||||
|
|
||||||
|
// Instantiate a strip of 30 LEDs on SPI Bus 0
|
||||||
|
var ledStrip = new lib.APA102(30, 0);
|
||||||
|
|
||||||
|
// Set all LEDs to blue
|
||||||
|
ledStrip.setAllLeds(31, 0, 0, 255);
|
||||||
|
|
||||||
|
// Set a mid-section to red
|
||||||
|
ledStrip.setLeds(10,20, 31, 255, 0, 0);
|
||||||
|
|
||||||
|
// Set a single led to green
|
||||||
|
ledStrip.setLed(15, 31, 0, 255, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// Exit
|
||||||
|
ledStrip = null;
|
||||||
|
process.exit(0);
|
51
examples/javascript/bme280.js
Normal file
51
examples/javascript/bme280.js
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Henry Bruce <henry.bruce@intel.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var bme280pkg = require('jsupm_bme280');
|
||||||
|
|
||||||
|
// Instantiate a BME280 Sensor on I2C sub-platform bus 0
|
||||||
|
var bme280 = new bme280pkg.BME280(512);
|
||||||
|
|
||||||
|
// update every second and print the values
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
// print detected value
|
||||||
|
console.log("Temperature: " + bme280.getTemperatureCelcius() + "C");
|
||||||
|
console.log("Humidity: " + bme280.getHumidityRelative() + "%");
|
||||||
|
console.log("Pressure: " + bme280.getPressurePa() + "Pa");
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
// When exiting: clear interval and print message
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
bme280 = null
|
||||||
|
bme280pkg = null;
|
||||||
|
console.log("Exiting");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
71
examples/javascript/bmi160.js
Normal file
71
examples/javascript/bmi160.js
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_bmi160');
|
||||||
|
|
||||||
|
// Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
var sensor = new sensorObj.BMI160();
|
||||||
|
|
||||||
|
var x = new sensorObj.new_floatp();
|
||||||
|
var y = new sensorObj.new_floatp();
|
||||||
|
var z = new sensorObj.new_floatp();
|
||||||
|
|
||||||
|
// Output data every half second until interrupted
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
sensor.getAccelerometer(x, y, z);
|
||||||
|
console.log("Accelerometer: AX: " + sensorObj.floatp_value(x) +
|
||||||
|
" AY: " + sensorObj.floatp_value(y) +
|
||||||
|
" AZ: " + sensorObj.floatp_value(z));
|
||||||
|
|
||||||
|
sensor.getGyroscope(x, y, z);
|
||||||
|
console.log("Gyroscope: GX: " + sensorObj.floatp_value(x) +
|
||||||
|
" AY: " + sensorObj.floatp_value(y) +
|
||||||
|
" AZ: " + sensorObj.floatp_value(z));
|
||||||
|
|
||||||
|
sensor.getMagnetometer(x, y, z);
|
||||||
|
console.log("Magnetometer: MX: " + sensorObj.floatp_value(x) +
|
||||||
|
" MY: " + sensorObj.floatp_value(y) +
|
||||||
|
" MZ: " + sensorObj.floatp_value(z));
|
||||||
|
|
||||||
|
console.log();
|
||||||
|
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
// exit on ^C
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting.");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
52
examples/javascript/curieimu.js
Normal file
52
examples/javascript/curieimu.js
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
/*
|
||||||
|
* Author: Ron Evans (@deadprogram)
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var mraa = require('mraa');
|
||||||
|
console.log('MRAA Version: ' + mraa.getVersion());
|
||||||
|
|
||||||
|
// open connection to Firmata
|
||||||
|
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0");
|
||||||
|
|
||||||
|
var curieImu = require('jsupm_curieimu');
|
||||||
|
var myCurie = new curieImu.CurieImu();
|
||||||
|
|
||||||
|
var outputStr;
|
||||||
|
var myInterval = setInterval(function()
|
||||||
|
{
|
||||||
|
myCurie.updateAccel();
|
||||||
|
outputStr = "accel: x " + myCurie.getAccelX()
|
||||||
|
+ " - y " + myCurie.getAccelY()
|
||||||
|
+ " - z " + myCurie.getAccelZ();
|
||||||
|
console.log(outputStr);
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
// Print message when exiting
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
clearInterval(myInterval);
|
||||||
|
console.log("Exiting");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
66
examples/javascript/cwlsxxa.js
Normal file
66
examples/javascript/cwlsxxa.js
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_cwlsxxa');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
// humidity and A2 for temperature
|
||||||
|
var sensor = new sensorObj.CWLSXXA(0, 1, 2);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
console.log("Temperature:", sensor.getTemperature(),
|
||||||
|
"C /", sensor.getTemperature(true), "F");
|
||||||
|
|
||||||
|
console.log("Humidity:", sensor.getHumidity(), "%");
|
||||||
|
|
||||||
|
console.log("CO2:", sensor.getCO2(), "ppm");
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
101
examples/javascript/e50hx.js
Normal file
101
examples/javascript/e50hx.js
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_e50hx');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
// You will need to edit this example to conform to your site and your
|
||||||
|
// devices, specifically the Device Object Instance ID passed to the
|
||||||
|
// constructor, and the arguments to initMaster() that are
|
||||||
|
// appropriate for your BACnet network.
|
||||||
|
|
||||||
|
var defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (process.argv.length > 2)
|
||||||
|
{
|
||||||
|
defaultDev = process.argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Using device " + defaultDev);
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an E50HX object for an E50HX device that has 1075425
|
||||||
|
// as it's unique Device Object Instance ID. NOTE: You will
|
||||||
|
// certainly want to change this to the correct value for your
|
||||||
|
// device(s).
|
||||||
|
var sensor = new sensorObj.E50HX(1075425);
|
||||||
|
|
||||||
|
// Initialize our BACnet master, if it has not already been
|
||||||
|
// initialized, with the device and baudrate, choosing 1000001 as
|
||||||
|
// our unique Device Object Instance ID, 2 as our MAC address and
|
||||||
|
// using default values for maxMaster and maxInfoFrames
|
||||||
|
sensor.initMaster(defaultDev, 38400, 1000001, 2);
|
||||||
|
|
||||||
|
// Uncomment to enable debugging output
|
||||||
|
// sensor.setDebug(true);
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
console.log("Device Description:", sensor.getDescription());
|
||||||
|
console.log("Device Location:", sensor.getLocation());
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
// update and print a few values every 5 seconds
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
console.log("System Voltage:",
|
||||||
|
sensor.getAnalogValue(sensorObj.E50HX.AV_System_Voltage),
|
||||||
|
" ",
|
||||||
|
sensor.getAnalogValueUnits(sensorObj.E50HX.AV_System_Voltage));
|
||||||
|
|
||||||
|
console.log("System Type:",
|
||||||
|
sensor.getAnalogValue(sensorObj.E50HX.AV_System_Type));
|
||||||
|
|
||||||
|
console.log("Energy Consumption:",
|
||||||
|
sensor.getAnalogInput(sensorObj.E50HX.AI_Energy),
|
||||||
|
" ",
|
||||||
|
sensor.getAnalogInputUnits(sensorObj.E50HX.AI_Energy));
|
||||||
|
|
||||||
|
console.log("Power Up Counter:",
|
||||||
|
sensor.getAnalogInput(sensorObj.E50HX.AI_Power_Up_Count));
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
115
examples/javascript/h803x.js
Normal file
115
examples/javascript/h803x.js
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_h803x');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
var defaultDev = "/dev/ttyUSB0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (process.argv.length > 2)
|
||||||
|
{
|
||||||
|
defaultDev = process.argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Using device " + defaultDev);
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
// default comm parameters (9600, 8, N, 2)
|
||||||
|
var sensor = new sensorObj.H803X(defaultDev, 1);
|
||||||
|
|
||||||
|
// output the Slave ID (manufacturer, model, serno)
|
||||||
|
console.log("Slave ID:", sensor.getSlaveID());
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// H8035 / H8036
|
||||||
|
console.log("Consumption (kWh):", sensor.getConsumption());
|
||||||
|
console.log("Real Power (kW):", sensor.getRealPower());
|
||||||
|
|
||||||
|
if (sensor.isH8036())
|
||||||
|
{
|
||||||
|
// The H8036 has much more data available...
|
||||||
|
|
||||||
|
console.log("Reactive Power (kVAR):", sensor.getReactivePower());
|
||||||
|
console.log("Apparent Power (kVA):", sensor.getApparentPower());
|
||||||
|
console.log("Power Factor:", sensor.getPowerFactor());
|
||||||
|
console.log("Volts Line to Line:", sensor.getVoltsLineToLine());
|
||||||
|
console.log("Volts Line to Neutral:", sensor.getVoltsLineToNeutral());
|
||||||
|
|
||||||
|
console.log("Current:", sensor.getCurrent());
|
||||||
|
|
||||||
|
console.log("Real Power Phase A (kW):", sensor.getRealPowerPhaseA());
|
||||||
|
console.log("Real Power Phase B (kW):", sensor.getRealPowerPhaseB());
|
||||||
|
console.log("Real Power Phase C (kW):", sensor.getRealPowerPhaseC());
|
||||||
|
|
||||||
|
console.log("Power Factor Phase A:", sensor.getPowerFactorPhaseA());
|
||||||
|
console.log("Power Factor Phase B:", sensor.getPowerFactorPhaseB());
|
||||||
|
console.log("Power Factor Phase C:", sensor.getPowerFactorPhaseC());
|
||||||
|
|
||||||
|
console.log("Volts Phase A to B:", sensor.getVoltsPhaseAToB());
|
||||||
|
console.log("Volts Phase B to C:", sensor.getVoltsPhaseBToC());
|
||||||
|
console.log("Volts Phase A to C:", sensor.getVoltsPhaseAToC());
|
||||||
|
console.log("Volts Phase A to Neutral: ",
|
||||||
|
sensor.getVoltsPhaseAToNeutral());
|
||||||
|
console.log("Volts Phase B to Neutral: ",
|
||||||
|
sensor.getVoltsPhaseBToNeutral());
|
||||||
|
console.log("Volts Phase C to Neutral: ",
|
||||||
|
sensor.getVoltsPhaseCToNeutral());
|
||||||
|
|
||||||
|
console.log("Current Phase A:", sensor.getCurrentPhaseA());
|
||||||
|
console.log("Current Phase B:", sensor.getCurrentPhaseB());
|
||||||
|
console.log("Current Phase C:", sensor.getCurrentPhaseC());
|
||||||
|
|
||||||
|
console.log("Avg Real Power (kW):", sensor.getAvgRealPower());
|
||||||
|
console.log("Min Real Power (kW):", sensor.getMinRealPower());
|
||||||
|
console.log("Max Real Power (kW):", sensor.getMaxRealPower());
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 2000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
@ -128,7 +128,7 @@ function runRadio()
|
|||||||
console.log("Received: " + resultStr);
|
console.log("Received: " + resultStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv < 0) // some sort of read error occured
|
if (rv < 0) // some sort of read error occurred
|
||||||
{
|
{
|
||||||
console.log("Port read error.");
|
console.log("Port read error.");
|
||||||
return;
|
return;
|
||||||
|
@ -90,7 +90,7 @@ function exit()
|
|||||||
|
|
||||||
// Load i2clcd module
|
// Load i2clcd module
|
||||||
var lcdObj = require('jsupm_i2clcd');
|
var lcdObj = require('jsupm_i2clcd');
|
||||||
var lcd = new lcdObj.SSD1306(6, 0x3c);
|
var lcd = new lcdObj.SSD1306(0, 0x3C);
|
||||||
var next = 0;
|
var next = 0;
|
||||||
|
|
||||||
lcd.clear();
|
lcd.clear();
|
||||||
|
70
examples/javascript/teams.js
Normal file
70
examples/javascript/teams.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_teams');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
// 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
// interface)
|
||||||
|
var sensor = new sensorObj.TEAMS(0, 165.0);
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
// is the sensor connected? (current >= 4ma)
|
||||||
|
console.log("Is Connected:", sensor.isConnected());
|
||||||
|
|
||||||
|
// print computed current on the loop. This includes the offset,
|
||||||
|
// if one was set by setOffsetMilliamps().
|
||||||
|
console.log("Milliamps:", sensor.getRawMilliamps());
|
||||||
|
|
||||||
|
// we show both C and F for temperature
|
||||||
|
console.log("Temperature:", sensor.getTemperature(),
|
||||||
|
"C /", sensor.getTemperature(true), "F");
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
77
examples/javascript/tex00.js
Normal file
77
examples/javascript/tex00.js
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_tex00');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
// this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
// (10k type 2) thermistor.
|
||||||
|
var sensor = new sensorObj.TEX00(0, 10000,
|
||||||
|
sensorObj.TEX00.STYPE_THERMISTOR_TED);
|
||||||
|
|
||||||
|
console.log("Minimum temperature:", sensor.getTemperatureRangeMin(),
|
||||||
|
"C");
|
||||||
|
console.log("Maximum temperature:", sensor.getTemperatureRangeMax(),
|
||||||
|
"C");
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
// update and print available values every second
|
||||||
|
setInterval(function()
|
||||||
|
{
|
||||||
|
// update our values from the sensor
|
||||||
|
sensor.update();
|
||||||
|
|
||||||
|
if (sensor.isOutOfRange())
|
||||||
|
{
|
||||||
|
console.log("Temperature out of range");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// we show both C and F for temperature
|
||||||
|
console.log("Temperature:", sensor.getTemperature(),
|
||||||
|
"C /", sensor.getTemperature(true), "F");
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("");
|
||||||
|
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
|
||||||
|
process.on('SIGINT', function()
|
||||||
|
{
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
});
|
@ -66,7 +66,7 @@ function getGPSInfo()
|
|||||||
process.stdout.write(GPSData)
|
process.stdout.write(GPSData)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rv < 0) // some sort of read error occured
|
if (rv < 0) // some sort of read error occurred
|
||||||
{
|
{
|
||||||
console.log("Port read error.");
|
console.log("Port read error.");
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
69
examples/javascript/vcap.js
Normal file
69
examples/javascript/vcap.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||||
|
/*jshint unused:true */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
var sensorObj = require('jsupm_vcap');
|
||||||
|
|
||||||
|
|
||||||
|
/************** Main code **************/
|
||||||
|
|
||||||
|
var defaultDev = "/dev/video0";
|
||||||
|
|
||||||
|
// if an argument was specified, use it as the device instead
|
||||||
|
if (process.argv.length > 2)
|
||||||
|
{
|
||||||
|
defaultDev = process.argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Using device " + defaultDev);
|
||||||
|
console.log("Initializing...");
|
||||||
|
|
||||||
|
// Instantiate an VCAP instance, using the specified video device
|
||||||
|
var sensor = new sensorObj.VCAP(defaultDev);
|
||||||
|
|
||||||
|
// enable some debug/verbose output
|
||||||
|
sensor.setDebug(true);
|
||||||
|
|
||||||
|
// This is just a hint. The kernel can change this to a lower
|
||||||
|
// resolution that the hardware supports. Use getWidth() and
|
||||||
|
// getHeight() methods to see what the kernel actually chose if you
|
||||||
|
// care.
|
||||||
|
sensor.setResolution(1920, 1080);
|
||||||
|
|
||||||
|
// capture an image
|
||||||
|
sensor.captureImage();
|
||||||
|
|
||||||
|
// convert and save it as a jpeg
|
||||||
|
sensor.saveImage("video-img1.jpg");
|
||||||
|
|
||||||
|
// make sure we clean up
|
||||||
|
sensor = null;
|
||||||
|
sensorObj.cleanUp();
|
||||||
|
sensorObj = null;
|
||||||
|
console.log("Exiting...");
|
||||||
|
process.exit(0);
|
||||||
|
|
48
examples/python/apa102.py
Normal file
48
examples/python/apa102.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
# Copyright (c) 2016 Yannick Adam
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_apa102 as mylib
|
||||||
|
|
||||||
|
# Instantiate a strip of 30 LEDs on SPI bus 0
|
||||||
|
ledStrip = mylib.APA102(30, 0, False)
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Setting all LEDs to Green"
|
||||||
|
ledStrip.setAllLeds(31, 0, 255, 0)
|
||||||
|
|
||||||
|
print "Setting LEDs between 10 and 20 to Red"
|
||||||
|
ledStrip.setLeds(10, 20, 31, 255, 0, 0)
|
||||||
|
|
||||||
|
print "Setting LED 15 to Blue"
|
||||||
|
ledStrip.setLed(15, 31, 0, 0, 255)
|
||||||
|
|
||||||
|
|
66
examples/python/bmi160.py
Normal file
66
examples/python/bmi160.py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_bmi160 as sensorObj
|
||||||
|
|
||||||
|
# Instantiate a BMI160 instance using default i2c bus and address
|
||||||
|
sensor = sensorObj.BMI160()
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
x = sensorObj.new_floatp()
|
||||||
|
y = sensorObj.new_floatp()
|
||||||
|
z = sensorObj.new_floatp()
|
||||||
|
|
||||||
|
while (1):
|
||||||
|
sensor.update()
|
||||||
|
sensor.getAccelerometer(x, y, z)
|
||||||
|
print "Accelerometer: AX: ", sensorObj.floatp_value(x),
|
||||||
|
print " AY: ", sensorObj.floatp_value(y),
|
||||||
|
print " AZ: ", sensorObj.floatp_value(z)
|
||||||
|
|
||||||
|
sensor.getGyroscope(x, y, z)
|
||||||
|
print "Gyroscope: GX: ", sensorObj.floatp_value(x),
|
||||||
|
print " GY: ", sensorObj.floatp_value(y),
|
||||||
|
print " GZ: ", sensorObj.floatp_value(z)
|
||||||
|
|
||||||
|
sensor.getMagnetometer(x, y, z)
|
||||||
|
print "Magnetometer: MX: ", sensorObj.floatp_value(x),
|
||||||
|
print " MY: ", sensorObj.floatp_value(y),
|
||||||
|
print " MZ: ", sensorObj.floatp_value(z)
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(.5)
|
56
examples/python/curieimu.py
Normal file
56
examples/python/curieimu.py
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# Author: Ron Evans (@deadprogram)
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
|
||||||
|
|
||||||
|
import mraa
|
||||||
|
print (mraa.getVersion())
|
||||||
|
|
||||||
|
# open connection to Firmata
|
||||||
|
mraa.addSubplatform(mraa.GENERIC_FIRMATA, "/dev/ttyACM0")
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_curieimu as curieimu
|
||||||
|
sensor = curieimu.CurieImu()
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
|
||||||
|
while(1):
|
||||||
|
sensor.updateAccel();
|
||||||
|
|
||||||
|
outputStr = "acc: gX {0} - gY {1} - gZ {2}".format(
|
||||||
|
sensor.getAccelX(), sensor.getAccelY(),
|
||||||
|
sensor.getAccelZ())
|
||||||
|
print outputStr
|
||||||
|
|
||||||
|
time.sleep(1)
|
61
examples/python/cwlsxxa.py
Normal file
61
examples/python/cwlsxxa.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_cwlsxxa as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an CWLSXXA instance, using A0 for CO2, A1 for
|
||||||
|
# humidity and A2 for temperature
|
||||||
|
sensor = sensorObj.CWLSXXA(0, 1, 2)
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
# we show both C and F for temperature
|
||||||
|
print "Temperature:", sensor.getTemperature(), "C /",
|
||||||
|
print sensor.getTemperature(True), "F"
|
||||||
|
|
||||||
|
print "Humidity:", sensor.getHumidity(), "%"
|
||||||
|
|
||||||
|
print "CO2:", sensor.getCO2(), "ppm"
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(1)
|
95
examples/python/e50hx.py
Normal file
95
examples/python/e50hx.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_e50hx as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting..."
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
# You will need to edit this example to conform to your site and your
|
||||||
|
# devices, specifically the Device Object Instance ID passed to the
|
||||||
|
# constructor, and the arguments to initMaster() that are
|
||||||
|
# appropriate for your BACnet network.
|
||||||
|
|
||||||
|
defaultDev = "/dev/ttyUSB0"
|
||||||
|
|
||||||
|
# if an argument was specified, use it as the device instead
|
||||||
|
if (len(sys.argv) > 1):
|
||||||
|
defaultDev = sys.argv[1]
|
||||||
|
|
||||||
|
print "Using device", defaultDev
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an E50HX object for an E50HX device that has 1075425
|
||||||
|
# as it's unique Device Object Instance ID. NOTE: You will
|
||||||
|
# certainly want to change this to the correct value for your
|
||||||
|
# device(s).
|
||||||
|
sensor = sensorObj.E50HX(1075425)
|
||||||
|
|
||||||
|
# Initialize our BACnet master, if it has not already been
|
||||||
|
# initialized, with the device and baudrate, choosing 1000001 as
|
||||||
|
# our unique Device Object Instance ID, 2 as our MAC address and
|
||||||
|
# using default values for maxMaster and maxInfoFrames
|
||||||
|
sensor.initMaster(defaultDev, 38400, 1000001, 2)
|
||||||
|
|
||||||
|
# Uncomment to enable debugging output
|
||||||
|
# sensor.setDebug(True);
|
||||||
|
|
||||||
|
# output the serial number and firmware revision
|
||||||
|
print
|
||||||
|
print "Device Description:", sensor.getDescription()
|
||||||
|
print "Device Location:", sensor.getLocation()
|
||||||
|
print
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
print "System Voltage:",
|
||||||
|
print sensor.getAnalogValue(sensorObj.E50HX.AV_System_Voltage),
|
||||||
|
print " ",
|
||||||
|
print sensor.getAnalogValueUnits(sensorObj.E50HX.AV_System_Voltage)
|
||||||
|
|
||||||
|
print "System Type:",
|
||||||
|
print sensor.getAnalogValue(sensorObj.E50HX.AV_System_Type)
|
||||||
|
|
||||||
|
print "Energy Consumption:",
|
||||||
|
print sensor.getAnalogInput(sensorObj.E50HX.AI_Energy),
|
||||||
|
print " ",
|
||||||
|
print sensor.getAnalogInputUnits(sensorObj.E50HX.AI_Energy)
|
||||||
|
|
||||||
|
print "Power Up Counter:",
|
||||||
|
print sensor.getAnalogInput(sensorObj.E50HX.AI_Power_Up_Count)
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(5)
|
106
examples/python/h803x.py
Normal file
106
examples/python/h803x.py
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_h803x as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting..."
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
defaultDev = "/dev/ttyUSB0"
|
||||||
|
|
||||||
|
# if an argument was specified, use it as the device instead
|
||||||
|
if (len(sys.argv) > 1):
|
||||||
|
defaultDev = sys.argv[1]
|
||||||
|
|
||||||
|
print "Using device", defaultDev
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an H803X instance, using MODBUS slave address 1, and
|
||||||
|
# default comm parameters (9600, 8, N, 2)
|
||||||
|
sensor = sensorObj.H803X(defaultDev, 1)
|
||||||
|
|
||||||
|
# output the serial number and firmware revision
|
||||||
|
print "Slave ID:", sensor.getSlaveID()
|
||||||
|
|
||||||
|
print
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
# H8035 / H8036
|
||||||
|
print "Consumption (kWh):", sensor.getConsumption()
|
||||||
|
print "Real Power (kW):", sensor.getRealPower()
|
||||||
|
|
||||||
|
if (sensor.isH8036()):
|
||||||
|
# The H8036 has much more data available...
|
||||||
|
|
||||||
|
print "Reactive Power (kVAR):", sensor.getReactivePower()
|
||||||
|
print "Apparent Power (kVA):", sensor.getApparentPower()
|
||||||
|
print "Power Factor:", sensor.getPowerFactor()
|
||||||
|
print "Volts Line to Line:", sensor.getVoltsLineToLine()
|
||||||
|
print "Volts Line to Neutral:", sensor.getVoltsLineToNeutral()
|
||||||
|
|
||||||
|
print "Current:", sensor.getCurrent()
|
||||||
|
|
||||||
|
print "Real Power Phase A (kW):", sensor.getRealPowerPhaseA()
|
||||||
|
print "Real Power Phase B (kW):", sensor.getRealPowerPhaseB()
|
||||||
|
print "Real Power Phase C (kW):", sensor.getRealPowerPhaseC()
|
||||||
|
|
||||||
|
print "Power Factor Phase A:", sensor.getPowerFactorPhaseA()
|
||||||
|
print "Power Factor Phase B:", sensor.getPowerFactorPhaseB()
|
||||||
|
print "Power Factor Phase C:", sensor.getPowerFactorPhaseC()
|
||||||
|
|
||||||
|
print "Volts Phase A to B:", sensor.getVoltsPhaseAToB()
|
||||||
|
print "Volts Phase B to C:", sensor.getVoltsPhaseBToC()
|
||||||
|
print "Volts Phase A to C:", sensor.getVoltsPhaseAToC()
|
||||||
|
print "Volts Phase A to Neutral: ",
|
||||||
|
print sensor.getVoltsPhaseAToNeutral()
|
||||||
|
print "Volts Phase B to Neutral: ",
|
||||||
|
print sensor.getVoltsPhaseBToNeutral()
|
||||||
|
print "Volts Phase C to Neutral: ",
|
||||||
|
print sensor.getVoltsPhaseCToNeutral()
|
||||||
|
|
||||||
|
print "Current Phase A:", sensor.getCurrentPhaseA()
|
||||||
|
print "Current Phase B:", sensor.getCurrentPhaseB()
|
||||||
|
print "Current Phase C:", sensor.getCurrentPhaseC()
|
||||||
|
|
||||||
|
print "Avg Real Power (kW):", sensor.getAvgRealPower()
|
||||||
|
print "Min Real Power (kW):", sensor.getMinRealPower()
|
||||||
|
print "Max Real Power (kW):", sensor.getMaxRealPower()
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(2)
|
@ -123,7 +123,7 @@ else:
|
|||||||
resultStr += radioBuffer.__getitem__(x)
|
resultStr += radioBuffer.__getitem__(x)
|
||||||
print "Received:", resultStr
|
print "Received:", resultStr
|
||||||
|
|
||||||
if (rv < 0): # some sort of read error occured
|
if (rv < 0): # some sort of read error occurred
|
||||||
print "Port read error."
|
print "Port read error."
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
myCounter += 1
|
myCounter += 1
|
||||||
|
65
examples/python/teams.py
Normal file
65
examples/python/teams.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_teams as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an TEAMS instance, using A0 for temperature, and
|
||||||
|
# 165.0 ohms for the rResistor value (for the libelium 4-20ma
|
||||||
|
# interface)
|
||||||
|
sensor = sensorObj.TEAMS(0, 165.0)
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
# is the sensor connected? (current >= 4ma)
|
||||||
|
print "Is Connected:", sensor.isConnected()
|
||||||
|
|
||||||
|
# print computed current on the loop. This includes the offset,
|
||||||
|
# if one was set by setOffsetMilliamps().
|
||||||
|
print "Milliamps:", sensor.getRawMilliamps()
|
||||||
|
|
||||||
|
# we show both C and F for temperature
|
||||||
|
print "Temperature:", sensor.getTemperature(), "C /",
|
||||||
|
print sensor.getTemperature(True), "F"
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(1)
|
65
examples/python/tex00.py
Normal file
65
examples/python/tex00.py
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_tex00 as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting"
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an TEX00 instance, using A0 for the analog input. In
|
||||||
|
# this example, we are using a 10K Ohm balance resistor and a TED
|
||||||
|
# (10k type 2) thermistor.
|
||||||
|
sensor = sensorObj.TEX00(0, 10000, sensorObj.TEX00.STYPE_THERMISTOR_TED)
|
||||||
|
|
||||||
|
print "Minimum temperature:", sensor.getTemperatureRangeMin(), "C"
|
||||||
|
print "Maximum temperature:", sensor.getTemperatureRangeMax(), "C"
|
||||||
|
print
|
||||||
|
|
||||||
|
# update and print available values every second
|
||||||
|
while (1):
|
||||||
|
# update our values from the sensor
|
||||||
|
sensor.update()
|
||||||
|
|
||||||
|
if (sensor.isOutOfRange()):
|
||||||
|
print "Temperature out of range"
|
||||||
|
else:
|
||||||
|
# we show both C and F for temperature
|
||||||
|
print "Temperature:", sensor.getTemperature(), "C /",
|
||||||
|
print sensor.getTemperature(True), "F"
|
||||||
|
|
||||||
|
print
|
||||||
|
time.sleep(1)
|
@ -73,7 +73,7 @@ def getGPSInfo():
|
|||||||
GPSData += nmeaBuffer.__getitem__(x)
|
GPSData += nmeaBuffer.__getitem__(x)
|
||||||
sys.stdout.write(GPSData)
|
sys.stdout.write(GPSData)
|
||||||
|
|
||||||
if (rv < 0): # some sort of read error occured
|
if (rv < 0): # some sort of read error occurred
|
||||||
print "Port read error."
|
print "Port read error."
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
67
examples/python/vcap.py
Normal file
67
examples/python/vcap.py
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
# Copyright (c) 2016 Intel Corporation.
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
# a copy of this software and associated documentation files (the
|
||||||
|
# "Software"), to deal in the Software without restriction, including
|
||||||
|
# without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
# permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
# the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be
|
||||||
|
# included in all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
import time, sys, signal, atexit
|
||||||
|
import pyupm_vcap as sensorObj
|
||||||
|
|
||||||
|
## Exit handlers ##
|
||||||
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
def SIGINTHandler(signum, frame):
|
||||||
|
raise SystemExit
|
||||||
|
|
||||||
|
# This function lets you run code on exit
|
||||||
|
def exitHandler():
|
||||||
|
print "Exiting..."
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Register exit handlers
|
||||||
|
atexit.register(exitHandler)
|
||||||
|
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||||
|
|
||||||
|
defaultDev = "/dev/video0"
|
||||||
|
|
||||||
|
# if an argument was specified, use it as the device instead
|
||||||
|
if (len(sys.argv) > 1):
|
||||||
|
defaultDev = sys.argv[1]
|
||||||
|
|
||||||
|
print "Using device", defaultDev
|
||||||
|
print "Initializing..."
|
||||||
|
|
||||||
|
# Instantiate an VCAP instance, using the specified video device
|
||||||
|
sensor = sensorObj.VCAP(defaultDev)
|
||||||
|
|
||||||
|
# enable some debug/verbose output
|
||||||
|
sensor.setDebug(True);
|
||||||
|
|
||||||
|
# This is just a hint. The kernel can change this to a lower
|
||||||
|
# resolution that the hardware supports. Use getWidth() and
|
||||||
|
# getHeight() methods to see what the kernel actually chose if you
|
||||||
|
# care.
|
||||||
|
sensor.setResolution(1920, 1080);
|
||||||
|
|
||||||
|
# capture an image
|
||||||
|
sensor.captureImage();
|
||||||
|
|
||||||
|
# convert and save it as a jpeg
|
||||||
|
sensor.saveImage("video-img1.jpg");
|
||||||
|
|
@ -28,6 +28,11 @@ endmacro (upm_CREATE_INSTALL_PKGCONFIG)
|
|||||||
|
|
||||||
macro(upm_SWIG_PYTHON)
|
macro(upm_SWIG_PYTHON)
|
||||||
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
||||||
|
|
||||||
|
include_directories (
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||||
|
)
|
||||||
|
|
||||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||||
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
set_source_files_properties (pyupm_${libname}.i PROPERTIES SWIG_FLAGS "-I${CMAKE_CURRENT_BINARY_DIR}/..")
|
||||||
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
swig_add_module (pyupm_${libname} python pyupm_${libname}.i ${module_src})
|
||||||
@ -39,23 +44,39 @@ macro(upm_SWIG_PYTHON)
|
|||||||
)
|
)
|
||||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_pyupm_${libname}.so
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/_pyupm_${libname}.so
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/pyupm_${libname}.py
|
${CMAKE_CURRENT_BINARY_DIR}/pyupm_${libname}.py
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/
|
DESTINATION ${LIB_INSTALL_DIR}/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages/
|
||||||
COMPONENT ${libname})
|
COMPONENT ${libname})
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
macro(upm_SWIG_NODE)
|
macro(upm_SWIG_NODE)
|
||||||
if (BUILDSWIGNODE AND BUILDSWIG)
|
if (BUILDSWIGNODE AND BUILDSWIG)
|
||||||
|
# SWIG treats SWIG_FLAGS as a list and not a string so semicolon seperation is
|
||||||
|
# required. This hardcodes V8_VERSION to be <10 but I assume that's not going
|
||||||
|
# to be a problem for a little while! SWIG uses a padded SWIG_V8 version which
|
||||||
|
# we hack together from our findnode module.
|
||||||
|
set (V8_VERSION_HEX 0x0${V8_VERSION_MAJOR}${V8_VERSION_MINOR}${V8_VERSION_PATCH})
|
||||||
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
|
while (V8_VERSION_HEX_length LESS 8)
|
||||||
|
set (V8_VERSION_HEX "${V8_VERSION_HEX}0")
|
||||||
|
string (LENGTH "${V8_VERSION_HEX}" V8_VERSION_HEX_length)
|
||||||
|
endwhile ()
|
||||||
|
|
||||||
|
include_directories (
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/..
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property (SOURCE jsupm_${libname}.i PROPERTY SWIG_FLAGS "-node" "-DV8_VERSION=${V8_VERSION_HEX}")
|
||||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
set_source_files_properties (jsupm_${libname}.i PROPERTIES CPLUSPLUS ON)
|
||||||
set_source_files_properties (jsupm_${libname}.i PROPERTIES SWIG_FLAGS "-node")
|
|
||||||
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
swig_add_module (jsupm_${libname} javascript jsupm_${libname}.i ${module_src})
|
||||||
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
swig_link_libraries (jsupm_${libname} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||||
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
target_include_directories ( ${SWIG_MODULE_jsupm_${libname}_REAL_NAME}
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${NODE_INCLUDE_DIRS}"
|
"${NODE_INCLUDE_DIRS}"
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties (jsupm_${libname} PROPERTIES
|
set_target_properties (jsupm_${libname} PROPERTIES
|
||||||
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=0x0${V8_DEFINE_STRING}"
|
COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -DBUILDING_NODE_EXTENSION -DSWIG_V8_VERSION=${V8_VERSION_HEX}"
|
||||||
PREFIX ""
|
PREFIX ""
|
||||||
SUFFIX ".node"
|
SUFFIX ".node"
|
||||||
)
|
)
|
||||||
@ -65,12 +86,28 @@ macro(upm_SWIG_NODE)
|
|||||||
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
message(FATAL_ERROR " **ERROR** GCC 4.7 or above is required to compile jsupm_${libname} ")
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (NOT ENABLECXX11)
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD 11)
|
||||||
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
set_property (TARGET jsupm_${libname} PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
if (CMAKE_VERSION VERSION_LESS "3.1")
|
||||||
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||||
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.7")
|
||||||
|
message (FATAL_ERROR " FATAL ERROR: GNU gcc compiler is also too old (need 4.7+, but ${CMAKE_CXX_COMPILER_VERSION}) and does not support C++11 standard.")
|
||||||
|
endif ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=gnu++11")
|
||||||
|
else ()
|
||||||
|
set (UPM_CXX11_WORKAROUND_OPTION "-std=c++11")
|
||||||
|
endif ()
|
||||||
|
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${UPM_CXX11_WORKAROUND_OPTION} ")
|
||||||
|
endif ()
|
||||||
|
endif ()
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
createpackagejson(${libname})
|
createpackagejson(${libname})
|
||||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/jsupm_${libname}.node
|
||||||
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
||||||
endif()
|
endif()
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
@ -100,8 +137,8 @@ macro(upm_SWIG_JAVA)
|
|||||||
PREFIX "lib"
|
PREFIX "lib"
|
||||||
SUFFIX ".so"
|
SUFFIX ".so"
|
||||||
)
|
)
|
||||||
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
install (TARGETS javaupm_${libname} LIBRARY DESTINATION ${LIB_INSTALL_DIR})
|
||||||
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar DESTINATION ${CMAKE_INSTALL_LIBDIR}/../lib/java)
|
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/upm_${libname}.jar DESTINATION ${LIB_INSTALL_DIR}/../lib/java)
|
||||||
|
|
||||||
if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
|
if (NOT DEFINED $ENV{JAVA_HOME_NATIVE})
|
||||||
set (JAVAC $ENV{JAVA_HOME}/bin/javac)
|
set (JAVAC $ENV{JAVA_HOME}/bin/javac)
|
||||||
@ -129,7 +166,7 @@ macro(upm_doxygen)
|
|||||||
set (classname ${libname})
|
set (classname ${libname})
|
||||||
endif()
|
endif()
|
||||||
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
||||||
if (BUILDSWIG)
|
if (BUILDSWIGPYTHON AND BUILDSWIG)
|
||||||
add_dependencies (_pyupm_${libname} pyupm_doxy2swig)
|
add_dependencies (_pyupm_${libname} pyupm_doxy2swig)
|
||||||
add_dependencies (pydoc _pyupm_${libname})
|
add_dependencies (pydoc _pyupm_${libname})
|
||||||
else ()
|
else ()
|
||||||
@ -139,34 +176,43 @@ macro(upm_doxygen)
|
|||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
if (SWIG_FOUND)
|
if (SWIG_FOUND)
|
||||||
if(BUILDSWIGPYTHON)
|
if (BUILDSWIGPYTHON)
|
||||||
find_package (PythonLibs)
|
if(NOT PYTHONLIBS_FOUND)
|
||||||
|
find_package (PythonLibs ${PYTHONBUILD_VERSION} REQUIRED)
|
||||||
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
string (REPLACE "." ";" PYTHON_VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
|
||||||
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
list (GET PYTHON_VERSION_LIST 0 PYTHON_VERSION_MAJOR)
|
||||||
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
list (GET PYTHON_VERSION_LIST 1 PYTHON_VERSION_MINOR)
|
||||||
|
endif()
|
||||||
endif(BUILDSWIGPYTHON)
|
endif(BUILDSWIGPYTHON)
|
||||||
if(BUILDSWIGNODE)
|
if (BUILDSWIGNODE)
|
||||||
if(NOT NODE_FOUND)
|
if(NOT NODE_FOUND)
|
||||||
find_package(Node)
|
find_package(Node)
|
||||||
endif()
|
endif()
|
||||||
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
if(SWIG_VERSION VERSION_LESS 3.0.5 AND NODE_VERSION_STRING VERSION_GREATER 0.12)
|
||||||
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
message("WARNING - SWIG 3.0.5+ required for building with nodejs 0.12. Current version is ${SWIG_VERSION}")
|
||||||
endif()
|
endif()
|
||||||
find_path (NODE_ROOT_DIR "node/node.h")
|
find_path (NODE_ROOT_DIR "include/node/node.h")
|
||||||
set (NODE_INCLUDE_DIRS
|
set (NODE_INCLUDE_DIRS
|
||||||
${NODE_ROOT_DIR}/src
|
${NODE_ROOT_DIR}/include/src
|
||||||
${NODE_ROOT_DIR}/node
|
${NODE_ROOT_DIR}/include/node
|
||||||
${NODE_ROOT_DIR}/deps/v8/include
|
${NODE_ROOT_DIR}/include/deps/v8/include
|
||||||
${NODE_ROOT_DIR}/deps/uv/include
|
${NODE_ROOT_DIR}/include/deps/uv/include
|
||||||
)
|
)
|
||||||
macro(createpackagejson)
|
macro(createpackagejson)
|
||||||
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
configure_file (${PROJECT_SOURCE_DIR}/src/package.json.in ${CMAKE_CURRENT_BINARY_DIR}/package.json @ONLY)
|
||||||
|
# If a CMAKE_INSTALL_PREFIX has NOT been provided, set NODE_MODULE_INSTALL_PATH
|
||||||
|
# base on the NODE_ROOT_DIR.
|
||||||
|
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||||
|
set (NODE_MODULE_INSTALL_PATH ${NODE_ROOT_DIR}/lib/node_modules/jsupm_${libname}/)
|
||||||
|
# If a CMAKE_INSTALL_PREFIX has been provided, set NODE_MODULE_INSTALL_PATH
|
||||||
|
# relative to the provided install directory.
|
||||||
|
else ()
|
||||||
|
set (NODE_MODULE_INSTALL_PATH ${CMAKE_INSTALL_PREFIX}/lib/node_modules/jsupm_${libname}/)
|
||||||
|
endif ()
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/package.json
|
||||||
DESTINATION lib/node_modules/jsupm_${libname} COMPONENT ${libname})
|
DESTINATION ${NODE_MODULE_INSTALL_PATH} COMPONENT ${libname})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
|
||||||
endif(BUILDSWIGNODE)
|
endif(BUILDSWIGNODE)
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
macro(upm_module_init)
|
macro(upm_module_init)
|
||||||
@ -175,7 +221,7 @@ macro(upm_module_init)
|
|||||||
foreach (linkflag ${ARGN})
|
foreach (linkflag ${ARGN})
|
||||||
target_link_libraries (${libname} ${linkflag})
|
target_link_libraries (${libname} ${linkflag})
|
||||||
endforeach ()
|
endforeach ()
|
||||||
include_directories (${MRAA_INCLUDE_DIRS} .)
|
include_directories (${MRAA_INCLUDE_DIRS} . ..)
|
||||||
target_link_libraries (${libname} ${MRAA_LIBRARIES})
|
target_link_libraries (${libname} ${MRAA_LIBRARIES})
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
${libname}
|
${libname}
|
||||||
@ -183,7 +229,7 @@ macro(upm_module_init)
|
|||||||
SOVERSION ${upm_VERSION_MAJOR}
|
SOVERSION ${upm_VERSION_MAJOR}
|
||||||
VERSION ${upm_VERSION_STRING}
|
VERSION ${upm_VERSION_STRING}
|
||||||
)
|
)
|
||||||
upm_create_install_pkgconfig (upm-${libname}.pc ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
upm_create_install_pkgconfig (upm-${libname}.pc ${LIB_INSTALL_DIR}/pkgconfig)
|
||||||
if (SWIG_FOUND)
|
if (SWIG_FOUND)
|
||||||
if (NOT ";${PYTHONSWIG_BLACKLIST};" MATCHES ";${libname};")
|
if (NOT ";${PYTHONSWIG_BLACKLIST};" MATCHES ";${libname};")
|
||||||
upm_swig_python()
|
upm_swig_python()
|
||||||
@ -198,7 +244,7 @@ macro(upm_module_init)
|
|||||||
if (BUILDDOC)
|
if (BUILDDOC)
|
||||||
upm_doxygen()
|
upm_doxygen()
|
||||||
endif()
|
endif()
|
||||||
install(TARGETS ${libname} DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
install(TARGETS ${libname} DESTINATION ${LIB_INSTALL_DIR})
|
||||||
install (FILES ${module_h} DESTINATION include/upm COMPONENT ${libname})
|
install (FILES ${module_h} DESTINATION include/upm COMPONENT ${libname})
|
||||||
|
|
||||||
if (IPK)
|
if (IPK)
|
||||||
|
@ -30,15 +30,63 @@ ADS1015::setSPS(ADSSAMPLERATE rate){
|
|||||||
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
updateConfigRegister((m_config_reg & ~ADS1X15_DR_MASK) | rate);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1015::ADS1015(int bus, uint8_t address) : ADS1X15(bus, address) {
|
ADS1015::ADS1015(int bus, uint8_t address, float vref) : ADS1X15(bus, address) {
|
||||||
m_name = "ADS1015";
|
m_name = "ADS1015";
|
||||||
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
m_conversionDelay = ADS1015_CONVERSIONDELAY;
|
||||||
m_bitShift = 4;
|
m_bitShift = 4;
|
||||||
ADS1X15::getCurrentConfig();
|
ADS1X15::getCurrentConfig();
|
||||||
|
if (vref < 0.0 || vref > 6.144)
|
||||||
|
UPM_THROW("vref out of range");
|
||||||
|
else if (vref > 4.096)
|
||||||
|
setGain(GAIN_TWOTHIRDS);
|
||||||
|
else if (vref > 2.048)
|
||||||
|
setGain(GAIN_ONE);
|
||||||
|
else if (vref > 1.024)
|
||||||
|
setGain(GAIN_TWO);
|
||||||
|
else if (vref > 0.512)
|
||||||
|
setGain(GAIN_FOUR);
|
||||||
|
else if (vref > 0.256)
|
||||||
|
setGain(GAIN_EIGHT);
|
||||||
|
else
|
||||||
|
setGain(GAIN_SIXTEEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
ADS1015::~ADS1015(){};
|
ADS1015::~ADS1015(){};
|
||||||
|
|
||||||
|
const char*
|
||||||
|
ADS1015::getModuleName() {
|
||||||
|
return m_name.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
ADS1015::getNumInputs() {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
ADS1015::getResolutionInBits() {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t
|
||||||
|
ADS1015::getRawValue(unsigned int input) {
|
||||||
|
ADS1X15::ADSMUXMODE mode = getMuxMode(input);
|
||||||
|
updateConfigRegister((m_config_reg & ~ADS1X15_MUX_MASK) | mode, true);
|
||||||
|
usleep(m_conversionDelay);
|
||||||
|
uint16_t value = i2c->readWordReg(ADS1X15_REG_POINTER_CONVERT);
|
||||||
|
value = value >> m_bitShift;
|
||||||
|
return swapWord(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
float
|
||||||
|
ADS1015::getVoltage(unsigned int input) {
|
||||||
|
ADSMUXMODE mode = getMuxMode(input);
|
||||||
|
return getSample(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Private functions
|
//Private functions
|
||||||
float
|
float
|
||||||
ADS1015::getMultiplier(void){
|
ADS1015::getMultiplier(void){
|
||||||
@ -99,4 +147,20 @@ ADS1015::setDelay(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ADS1X15::ADSMUXMODE
|
||||||
|
ADS1015::getMuxMode(unsigned int input) {
|
||||||
|
ADS1X15::ADSMUXMODE mode;
|
||||||
|
switch (input) {
|
||||||
|
case 0:
|
||||||
|
return SINGLE_0;
|
||||||
|
case 1:
|
||||||
|
return SINGLE_1;
|
||||||
|
case 2:
|
||||||
|
return SINGLE_2;
|
||||||
|
case 3:
|
||||||
|
return SINGLE_3;
|
||||||
|
default:
|
||||||
|
UPM_THROW("Invalid input");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "ads1x15.h"
|
#include "ads1x15.h"
|
||||||
|
#include "upm/iADC.h"
|
||||||
|
|
||||||
|
#define ADS1015_VREF 2.048
|
||||||
|
|
||||||
/*=========================================================================
|
/*=========================================================================
|
||||||
CONVERSION DELAY (in microS)
|
CONVERSION DELAY (in microS)
|
||||||
@ -82,7 +83,7 @@ namespace upm {
|
|||||||
* @image html ads1015.jpg
|
* @image html ads1015.jpg
|
||||||
* @snippet ads1x15.cxx Interesting
|
* @snippet ads1x15.cxx Interesting
|
||||||
*/
|
*/
|
||||||
class ADS1015 : public ADS1X15 {
|
class ADS1015 : public ADS1X15, public IADC {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -111,12 +112,16 @@ namespace upm {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADS1X15 constructor
|
* ADS1015 constructor
|
||||||
|
*
|
||||||
|
* This constructor includes a vref parameter that can be used
|
||||||
|
* to set gain so it matches full scale value of input
|
||||||
*
|
*
|
||||||
* @param bus i2c bus the sensor is attached to.
|
* @param bus i2c bus the sensor is attached to.
|
||||||
* @param address. Device address. Default is 0x48.
|
* @param address. Optional device address. Default is 0x48.
|
||||||
|
* @param vref. Optional reference (i.e. half full swing) voltage. Default is 2.048V
|
||||||
*/
|
*/
|
||||||
ADS1015 (int bus, uint8_t address = 0x48);
|
ADS1015 (int bus, uint8_t address = 0x48, float vref = ADS1015_VREF);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ADS1X15 destructor
|
* ADS1X15 destructor
|
||||||
@ -132,9 +137,48 @@ namespace upm {
|
|||||||
*/
|
*/
|
||||||
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
void setSPS(ADSSAMPLERATE rate = SPS_1600);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get number of inputs
|
||||||
|
*
|
||||||
|
* @return number of inputs
|
||||||
|
*/
|
||||||
|
unsigned int getNumInputs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read current value for current single ended analogue input
|
||||||
|
*
|
||||||
|
* @return current conversion value
|
||||||
|
*/
|
||||||
|
uint16_t getRawValue(unsigned int input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read current voltage for current single ended analogue input
|
||||||
|
*
|
||||||
|
* @return current voltage
|
||||||
|
*/
|
||||||
|
float getVoltage(unsigned int input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read current voltage for current single ended analogue input
|
||||||
|
*
|
||||||
|
* @return current voltage
|
||||||
|
*/
|
||||||
|
unsigned int getResolutionInBits();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns module name
|
||||||
|
*
|
||||||
|
* @return modulename as const char*
|
||||||
|
*/
|
||||||
|
const char* getModuleName();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float getMultiplier(void);
|
float getMultiplier(void);
|
||||||
void setDelay(void);
|
void setDelay(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
ADS1X15::ADSMUXMODE getMuxMode(unsigned int input);
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ namespace upm {
|
|||||||
/**
|
/**
|
||||||
* Set the zero point. This is the point measured and averaged
|
* Set the zero point. This is the point measured and averaged
|
||||||
* when the sensor is not moving. It is set at construction time
|
* when the sensor is not moving. It is set at construction time
|
||||||
* (averaged over a number of samples), but can be overriden here.
|
* (averaged over a number of samples), but can be overridden here.
|
||||||
*
|
*
|
||||||
* @param zeroPoint The averaged zero point of the sensor at rest
|
* @param zeroPoint The averaged zero point of the sensor at rest
|
||||||
*/
|
*/
|
||||||
|
@ -233,7 +233,8 @@ AM2315::i2cWriteReg(uint8_t reg, uint8_t* data, uint8_t ilen)
|
|||||||
uint8_t
|
uint8_t
|
||||||
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
|
AM2315::i2cReadReg(int reg, uint8_t* data, int ilen)
|
||||||
{
|
{
|
||||||
uint8_t tdata[16] = { AM2315_READ, reg, ilen };
|
uint8_t tdata[16] = { AM2315_READ, static_cast<uint8_t>(reg),
|
||||||
|
static_cast<uint8_t>(ilen) };
|
||||||
|
|
||||||
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
mraa_result_t ret = mraa_i2c_address(m_i2ControlCtx, m_controlAddr);
|
||||||
int iLoops = 5;
|
int iLoops = 5;
|
||||||
|
5
src/apa102/CMakeLists.txt
Normal file
5
src/apa102/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
set (libname "apa102")
|
||||||
|
set (libdescription "upm apa102 led strip spi output module")
|
||||||
|
set (module_src ${libname}.cxx)
|
||||||
|
set (module_h ${libname}.h)
|
||||||
|
upm_module_init()
|
166
src/apa102/apa102.cxx
Normal file
166
src/apa102/apa102.cxx
Normal file
@ -0,0 +1,166 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "apa102.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
|
||||||
|
APA102::APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode, int8_t csn)
|
||||||
|
: m_ledCount(ledCount), m_batchMode(batchMode)
|
||||||
|
{
|
||||||
|
mraa::Result res = mraa::SUCCESS;
|
||||||
|
m_leds = NULL;
|
||||||
|
|
||||||
|
// Optional chip select pin
|
||||||
|
m_csnPinCtx = NULL;
|
||||||
|
if (csn > -1) {
|
||||||
|
m_csnPinCtx = new mraa::Gpio(csn);
|
||||||
|
res = m_csnPinCtx->dir(mraa::DIR_OUT);
|
||||||
|
if (res != mraa::SUCCESS) {
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||||
|
": GPIO failed to set direction");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CSOff();
|
||||||
|
// Initialize SPI
|
||||||
|
m_spi = new mraa::Spi(spiBus);
|
||||||
|
|
||||||
|
// Initialize LED array
|
||||||
|
uint16_t endFrameLength = (m_ledCount + 15) / 16; // End frame should be (leds/2) bits
|
||||||
|
m_frameLength = endFrameLength + (m_ledCount + 1) * 4;
|
||||||
|
if ((m_leds = (uint8_t*) malloc(m_frameLength))) {
|
||||||
|
memset(m_leds, 0x00, m_frameLength - 4); // Clear state
|
||||||
|
memset(&m_leds[m_frameLength - endFrameLength], 0xFF, endFrameLength); // Frame End
|
||||||
|
|
||||||
|
// Need to set the brightness to "0" for each Led
|
||||||
|
for (int i = 1; i <= m_ledCount; i++) {
|
||||||
|
m_leds[i * 4] = 224;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
": Failed to allocate memory for LED Strip");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
APA102::~APA102()
|
||||||
|
{
|
||||||
|
// Clear leds
|
||||||
|
if (m_leds) {
|
||||||
|
free(m_leds);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear SPI
|
||||||
|
if (m_spi) {
|
||||||
|
delete m_spi;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear GPIO
|
||||||
|
if (m_csnPinCtx) {
|
||||||
|
delete m_csnPinCtx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
setLeds(ledIdx, ledIdx, brightness, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
setLeds(0, m_ledCount - 1, brightness, r, g, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
{
|
||||||
|
uint16_t s_idx = (startIdx + 1) * 4;
|
||||||
|
uint16_t e_idx = (endIdx + 1) * 4;
|
||||||
|
|
||||||
|
for (uint16_t i = s_idx; i <= e_idx; i += 4) {
|
||||||
|
m_leds[i] = brightness | 224;
|
||||||
|
m_leds[i + 1] = b;
|
||||||
|
m_leds[i + 2] = g;
|
||||||
|
m_leds[i + 3] = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_batchMode) {
|
||||||
|
pushState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
|
||||||
|
{
|
||||||
|
uint16_t s_idx = (startIdx + 1) * 4;
|
||||||
|
memcpy(&m_leds[s_idx], colors, (endIdx - startIdx + 1) * 4);
|
||||||
|
|
||||||
|
if (!m_batchMode) {
|
||||||
|
pushState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
APA102::pushState(void)
|
||||||
|
{
|
||||||
|
CSOn();
|
||||||
|
m_spi->write(m_leds, m_frameLength);
|
||||||
|
CSOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* **************
|
||||||
|
* private area
|
||||||
|
* **************
|
||||||
|
*/
|
||||||
|
|
||||||
|
mraa::Result
|
||||||
|
APA102::CSOn()
|
||||||
|
{
|
||||||
|
if (m_csnPinCtx) {
|
||||||
|
return m_csnPinCtx->write(HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
mraa::Result
|
||||||
|
APA102::CSOff()
|
||||||
|
{
|
||||||
|
if (m_csnPinCtx) {
|
||||||
|
return m_csnPinCtx->write(LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mraa::ERROR_FEATURE_NOT_SUPPORTED;
|
||||||
|
}
|
143
src/apa102/apa102.h
Normal file
143
src/apa102/apa102.h
Normal file
@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* Author: Yannick Adam <yannick.adam@gmail.com>
|
||||||
|
* Copyright (c) 2016 Yannick Adam
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <mraa/gpio.hpp>
|
||||||
|
#include <mraa/spi.hpp>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define HIGH 1
|
||||||
|
#define LOW 0
|
||||||
|
|
||||||
|
namespace upm
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @brief APA102 RGB LED Strip driver library
|
||||||
|
* @defgroup apa102 libupm-apa102
|
||||||
|
* @ingroup spi led
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library apa102
|
||||||
|
* @sensor apa102
|
||||||
|
* @comname APA102/DotStar LED Strip
|
||||||
|
* @type led
|
||||||
|
* @man adafruit
|
||||||
|
* @con spi
|
||||||
|
*
|
||||||
|
* @brief API for controlling APA102/DotStar RGB LED Strips
|
||||||
|
*
|
||||||
|
* APA102 LED Strips provide individually controllable LEDs through a SPI interface.
|
||||||
|
* For each LED, brightness (0-31) and RGB (0-255) values can be set.
|
||||||
|
*
|
||||||
|
* @image html apa102.jpg
|
||||||
|
* @snippet apa102.cxx Interesting
|
||||||
|
*/
|
||||||
|
class APA102
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* Instantiates a new APA102 LED Strip
|
||||||
|
*
|
||||||
|
* @param ledCount Number of APA102 leds in the strip
|
||||||
|
* @param spiBus SPI Bus number
|
||||||
|
* @param batchMode (optional) Immediately write to SPI (false, default) or wait for a pushState
|
||||||
|
* call (true)
|
||||||
|
* @param csn (optional) Chip Select Pin
|
||||||
|
*/
|
||||||
|
APA102(uint16_t ledCount, uint8_t spiBus, bool batchMode = false, int8_t csn = -1);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APA102 destructor
|
||||||
|
*/
|
||||||
|
~APA102();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the color for a single led
|
||||||
|
*
|
||||||
|
* @param ledIdx Index of the LED in the strip (0 based)
|
||||||
|
* @param brightness Brightness value (0-31)
|
||||||
|
* @param r Red component (0-255)
|
||||||
|
* @param g Green component (0-255)
|
||||||
|
* @param b Blue component (0-255)
|
||||||
|
*/
|
||||||
|
void setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the color for all leds
|
||||||
|
*
|
||||||
|
* @param brightness Brightness value (0-31)
|
||||||
|
* @param r Red component (0-255)
|
||||||
|
* @param g Green component (0-255)
|
||||||
|
* @param b Blue component (0-255)
|
||||||
|
*/
|
||||||
|
void setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the color for a range of leds
|
||||||
|
*
|
||||||
|
* @param startIdx Start index of the range of LEDs in the strip (0 based)
|
||||||
|
* @param endIdx End index of the range of LEDs in the strip (0 based)
|
||||||
|
* @param brightness Brightness value (0-31)
|
||||||
|
* @param r Red component (0-255)
|
||||||
|
* @param g Green component (0-255)
|
||||||
|
* @param b Blue component (0-255)
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_t b);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (Advanced) Manually control the colors of a range of LEDS
|
||||||
|
* Best used to maximize performance
|
||||||
|
*
|
||||||
|
* @param startIdx Start index of the range of LEDs to update (0 based)
|
||||||
|
* @param endIdx End index of the range of LEDs to update (0 based)
|
||||||
|
* @param colors Pointer to an array of bytes. Each color is described as the following:
|
||||||
|
* B1: Brightness (224-255) B2: Blue (0-255) B3: Green (0-255) B4: Red
|
||||||
|
*(0-255)
|
||||||
|
* No check done on the boundaries
|
||||||
|
*/
|
||||||
|
void setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Outputs the current LED data to the SPI bus
|
||||||
|
* Note: Only required if batch mode is set to TRUE
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void pushState();
|
||||||
|
|
||||||
|
private:
|
||||||
|
mraa::Spi* m_spi;
|
||||||
|
mraa::Gpio* m_csnPinCtx;
|
||||||
|
|
||||||
|
uint16_t m_ledCount;
|
||||||
|
uint8_t* m_leds;
|
||||||
|
uint16_t m_frameLength;
|
||||||
|
|
||||||
|
bool m_batchMode;
|
||||||
|
|
||||||
|
mraa::Result CSOn();
|
||||||
|
mraa::Result CSOff();
|
||||||
|
};
|
||||||
|
}
|
30
src/apa102/javaupm_apa102.i
Normal file
30
src/apa102/javaupm_apa102.i
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
%module javaupm_apa102
|
||||||
|
|
||||||
|
%include "../upm.i"
|
||||||
|
%include "typemaps.i"
|
||||||
|
|
||||||
|
%typemap(jtype) (uint8_t *colors) "byte[]"
|
||||||
|
%typemap(jstype) (uint8_t *colors) "byte[]"
|
||||||
|
%typemap(jni) (uint8_t *colors) "jbyteArray"
|
||||||
|
%typemap(javain) (uint8_t *colors) "$javainput"
|
||||||
|
|
||||||
|
%typemap(in) (uint8_t *colors) {
|
||||||
|
$1 = (uint8_t*)JCALL2(GetByteArrayElements, jenv, $input, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "apa102.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "apa102.h"
|
||||||
|
|
||||||
|
%pragma(java) jniclasscode=%{
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
System.loadLibrary("javaupm_apa102");
|
||||||
|
} catch (UnsatisfiedLinkError e) {
|
||||||
|
System.err.println("Native code library failed to load. \n" + e);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
19
src/apa102/jsupm_apa102.i
Normal file
19
src/apa102/jsupm_apa102.i
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
%module jsupm_apa102
|
||||||
|
|
||||||
|
%include "../upm.i"
|
||||||
|
%inline %{
|
||||||
|
#include <node_buffer.h>
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(in) (uint8_t *colors) {
|
||||||
|
if (!node::Buffer::HasInstance($input)) {
|
||||||
|
SWIG_exception_fail(SWIG_ERROR, "Expected a node Buffer");
|
||||||
|
}
|
||||||
|
$1 = (uint8_t*) node::Buffer::Data($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "apa102.h"
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "apa102.h"
|
||||||
|
%}
|
25
src/apa102/pyupm_apa102.i
Normal file
25
src/apa102/pyupm_apa102.i
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Include doxygen-generated documentation
|
||||||
|
%include "pyupm_doxy2swig.i"
|
||||||
|
|
||||||
|
%module pyupm_apa102
|
||||||
|
|
||||||
|
%include "../upm.i"
|
||||||
|
|
||||||
|
%feature("autodoc", "3");
|
||||||
|
|
||||||
|
// setLeds
|
||||||
|
%typemap(in) (uint8_t *colors) {
|
||||||
|
if (PyByteArray_Check($input)) {
|
||||||
|
$1 = (uint8_t*) PyByteArray_AsString($input);
|
||||||
|
} else {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "bytearray expected");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
%include "apa102.h"
|
||||||
|
|
||||||
|
%{
|
||||||
|
|
||||||
|
#include "apa102.h"
|
||||||
|
%}
|
24
src/bacnetmstp/CMakeLists.txt
Normal file
24
src/bacnetmstp/CMakeLists.txt
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
set (libname "bacnetmstp")
|
||||||
|
set (libdescription "upm driver module for BACnet MS/TP devices")
|
||||||
|
set (module_src ${libname}.cxx device-client.c)
|
||||||
|
set (module_h ${libname}.h)
|
||||||
|
|
||||||
|
pkg_search_module(BACNET libbacnet)
|
||||||
|
if (BACNET_FOUND)
|
||||||
|
set (reqlibname "libbacnet")
|
||||||
|
include_directories(${BACNET_INCLUDE_DIRS})
|
||||||
|
upm_module_init()
|
||||||
|
add_dependencies(${libname} ${BACNET_LIBRARIES})
|
||||||
|
target_link_libraries(${libname} ${BACNET_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||||
|
if (BUILDSWIG)
|
||||||
|
if (BUILDSWIGNODE)
|
||||||
|
swig_link_libraries (jsupm_${libname} ${BACNET_LIBRARIES} ${MRAA_LIBRARIES} ${NODE_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
if (BUILDSWIGPYTHON)
|
||||||
|
swig_link_libraries (pyupm_${libname} ${BACNET_LIBRARIES} ${PYTHON_LIBRARIES} ${MRAA_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
if (BUILDSWIGJAVA)
|
||||||
|
swig_link_libraries (javaupm_${libname} ${BACNET_LIBRARIES} ${MRAAJAVA_LDFLAGS} ${JAVA_LDFLAGS})
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif ()
|
880
src/bacnetmstp/bacnetmstp.cxx
Normal file
880
src/bacnetmstp/bacnetmstp.cxx
Normal file
@ -0,0 +1,880 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "bacnetmstp.h"
|
||||||
|
#include "handlers.h"
|
||||||
|
#include "client.h"
|
||||||
|
#include "txbuf.h"
|
||||||
|
#include "mstpdef.h"
|
||||||
|
|
||||||
|
using namespace upm;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// our singleton instance
|
||||||
|
BACNETMSTP* BACNETMSTP::m_instance = 0;
|
||||||
|
|
||||||
|
BACNETMSTP::BACNETMSTP()
|
||||||
|
{
|
||||||
|
// set defaults here
|
||||||
|
m_maxInfoFrames = DEFAULT_MAX_INFO_FRAMES;
|
||||||
|
m_maxMaster = DEFAULT_MAX_MASTER;
|
||||||
|
m_baudRate = 38400;
|
||||||
|
m_macAddr = DEFAULT_MAX_MASTER;
|
||||||
|
|
||||||
|
m_initialized = false;
|
||||||
|
|
||||||
|
// 60 sec, for MS/TP
|
||||||
|
m_adpuTimeoutMS = 60000;
|
||||||
|
|
||||||
|
m_deviceInstanceID = BACNET_MAX_INSTANCE;
|
||||||
|
|
||||||
|
memset(m_rxBuffer, 0, MAX_MPDU);
|
||||||
|
|
||||||
|
m_returnedValue = {0};
|
||||||
|
m_targetAddress = {0};
|
||||||
|
m_invokeID = 0;
|
||||||
|
m_errorDetected = false;
|
||||||
|
|
||||||
|
setDebug(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNETMSTP::~BACNETMSTP()
|
||||||
|
{
|
||||||
|
if (m_initialized)
|
||||||
|
datalink_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::setDebug(bool enable)
|
||||||
|
{
|
||||||
|
m_debugging = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::clearErrors()
|
||||||
|
{
|
||||||
|
m_errorType = BACERR_TYPE_NONE;
|
||||||
|
|
||||||
|
// empty out all of our error/reject/abort info
|
||||||
|
m_rejectReason = REJECT_REASON_OTHER;
|
||||||
|
m_rejectString.clear();
|
||||||
|
|
||||||
|
m_abortReason = ABORT_REASON_OTHER;
|
||||||
|
m_abortString.clear();
|
||||||
|
|
||||||
|
m_errorClass = ERROR_CLASS_DEVICE;
|
||||||
|
m_errorCode = ERROR_CODE_OTHER;
|
||||||
|
m_errorString.clear();
|
||||||
|
|
||||||
|
m_upmErrorString.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::handlerError(BACNET_ADDRESS* src,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
BACNET_ERROR_CLASS error_class,
|
||||||
|
BACNET_ERROR_CODE error_code)
|
||||||
|
{
|
||||||
|
if (instance()->m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": entered" << endl;
|
||||||
|
|
||||||
|
if (address_match(&(instance()->m_targetAddress), src) &&
|
||||||
|
(invoke_id == instance()->m_invokeID))
|
||||||
|
{
|
||||||
|
instance()->m_errorType = BACERR_TYPE_ERROR;
|
||||||
|
instance()->m_errorClass = error_class;
|
||||||
|
instance()->m_errorCode = error_code;
|
||||||
|
instance()->m_errorString =
|
||||||
|
bactext_error_class_name((int)error_class)
|
||||||
|
+ string(": ") + bactext_error_code_name((int)error_code);
|
||||||
|
|
||||||
|
instance()->m_errorDetected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::handlerAbort(BACNET_ADDRESS* src,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
uint8_t abort_reason,
|
||||||
|
bool server)
|
||||||
|
{
|
||||||
|
(void)server; // not used
|
||||||
|
|
||||||
|
if (instance()->m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": entered" << endl;
|
||||||
|
|
||||||
|
if (address_match(&(instance()->m_targetAddress), src) &&
|
||||||
|
(invoke_id == instance()->m_invokeID))
|
||||||
|
{
|
||||||
|
instance()->m_errorType = BACERR_TYPE_ABORT;
|
||||||
|
instance()->m_abortReason = abort_reason;
|
||||||
|
instance()->m_abortString =
|
||||||
|
bactext_abort_reason_name((int)abort_reason);
|
||||||
|
|
||||||
|
instance()->m_errorDetected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::handlerReject(BACNET_ADDRESS* src,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
uint8_t reject_reason)
|
||||||
|
{
|
||||||
|
if (instance()->m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": entered" << endl;
|
||||||
|
|
||||||
|
if (address_match(&(instance()->m_targetAddress), src) &&
|
||||||
|
(invoke_id == instance()->m_invokeID))
|
||||||
|
{
|
||||||
|
instance()->m_errorType = BACERR_TYPE_REJECT;
|
||||||
|
instance()->m_rejectReason = reject_reason;
|
||||||
|
instance()->m_rejectString =
|
||||||
|
bactext_reject_reason_name((int)reject_reason);
|
||||||
|
|
||||||
|
instance()->m_errorDetected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::handlerReadPropertyAck(uint8_t* service_request,
|
||||||
|
uint16_t service_len,
|
||||||
|
BACNET_ADDRESS* src,
|
||||||
|
BACNET_CONFIRMED_SERVICE_ACK_DATA* service_data)
|
||||||
|
{
|
||||||
|
int len = 0;
|
||||||
|
BACNET_READ_PROPERTY_DATA data;
|
||||||
|
|
||||||
|
if (address_match(&(instance()->m_targetAddress), src) &&
|
||||||
|
(service_data->invoke_id == instance()->m_invokeID))
|
||||||
|
{
|
||||||
|
if (instance()->m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": got readProp ack" << endl;
|
||||||
|
|
||||||
|
len = rp_ack_decode_service_request(service_request, service_len,
|
||||||
|
&data);
|
||||||
|
// FIXME: we don't currently handle arrays (len < service_len)
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
bacapp_decode_application_data(data.application_data,
|
||||||
|
data.application_data_len,
|
||||||
|
&(instance()->m_returnedValue));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// shouldn't happen?
|
||||||
|
cerr << __FUNCTION__ << ": decode app data failed" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::handlerWritePropertyAck(BACNET_ADDRESS* src,
|
||||||
|
uint8_t invoke_id)
|
||||||
|
{
|
||||||
|
if (address_match(&(instance()->m_targetAddress), src) &&
|
||||||
|
(invoke_id == instance()->m_invokeID))
|
||||||
|
{
|
||||||
|
if (instance()->m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": got writeProp ack" << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::initServiceHandlers()
|
||||||
|
{
|
||||||
|
// this is in device-client.c
|
||||||
|
Device_Init(NULL);
|
||||||
|
|
||||||
|
// These are service requests we must handle from other masters
|
||||||
|
|
||||||
|
// we need to handle who-is to support dynamic device binding to us
|
||||||
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is);
|
||||||
|
|
||||||
|
// handle i-am to support binding to other devices
|
||||||
|
apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind);
|
||||||
|
|
||||||
|
// set the handler for all the services we don't implement
|
||||||
|
|
||||||
|
// It is required to send the proper reject message...
|
||||||
|
apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service);
|
||||||
|
|
||||||
|
// we must implement read property (it's required)
|
||||||
|
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
|
handler_read_property);
|
||||||
|
|
||||||
|
// These are related to requests we make
|
||||||
|
|
||||||
|
// handle the data coming back from confirmed readProp requests
|
||||||
|
apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY,
|
||||||
|
handlerReadPropertyAck);
|
||||||
|
|
||||||
|
// handle the simple ack for confirmed writeProp requests
|
||||||
|
apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
|
||||||
|
handlerWritePropertyAck);
|
||||||
|
|
||||||
|
// handle any errors coming back
|
||||||
|
apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, handlerError);
|
||||||
|
apdu_set_abort_handler(handlerAbort);
|
||||||
|
apdu_set_reject_handler(handlerReject);
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNETMSTP* BACNETMSTP::instance()
|
||||||
|
{
|
||||||
|
if (!m_instance)
|
||||||
|
m_instance = new BACNETMSTP;
|
||||||
|
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BACNETMSTP::initMaster(std::string port, int baudRate,
|
||||||
|
int deviceInstanceID, int macAddr, int maxMaster,
|
||||||
|
int maxInfoFrames)
|
||||||
|
{
|
||||||
|
// first some checking
|
||||||
|
|
||||||
|
// if we are already initialized, then it's too late to change things now
|
||||||
|
if (m_initialized)
|
||||||
|
{
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": Instance is already initialized, ignored."
|
||||||
|
<< endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// baudrate
|
||||||
|
// The standard allows (as of at least 2010) the following baud rates
|
||||||
|
if ( !(baudRate == 9600 || baudRate == 19200 || baudRate == 38400
|
||||||
|
|| baudRate == 57600 || baudRate == 76800 || baudRate == 115200) )
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": baudRate must be 9600, 19200, 38400, "
|
||||||
|
+ " 57600, 76800, or 115200");
|
||||||
|
}
|
||||||
|
|
||||||
|
// maxMaster
|
||||||
|
// maxMaster must be less than or equal to 127
|
||||||
|
if (maxMaster < 0 || maxMaster > DEFAULT_MAX_MASTER)
|
||||||
|
{
|
||||||
|
throw std::out_of_range(std::string(__FUNCTION__)
|
||||||
|
+ ": maxMaster must be between 0 and "
|
||||||
|
+ std::to_string(DEFAULT_MAX_MASTER));
|
||||||
|
}
|
||||||
|
|
||||||
|
// As a master ourselves, we must have a MAC address also within the
|
||||||
|
// constraints of maxMaster
|
||||||
|
if (macAddr < 0 || macAddr > DEFAULT_MAX_MASTER)
|
||||||
|
{
|
||||||
|
throw std::out_of_range(std::string(__FUNCTION__)
|
||||||
|
+ ": macAddr must be between 0 and "
|
||||||
|
+ std::to_string(DEFAULT_MAX_MASTER));
|
||||||
|
}
|
||||||
|
|
||||||
|
// this should be unique on the network
|
||||||
|
if (deviceInstanceID >= BACNET_MAX_INSTANCE)
|
||||||
|
{
|
||||||
|
throw std::out_of_range(std::string(__FUNCTION__)
|
||||||
|
+ ": deviceInstanceID must be less than "
|
||||||
|
+ std::to_string(BACNET_MAX_INSTANCE)
|
||||||
|
+ ", and must be unique on the network");
|
||||||
|
}
|
||||||
|
|
||||||
|
m_port = port;
|
||||||
|
m_baudRate = baudRate;
|
||||||
|
m_maxInfoFrames = maxInfoFrames;
|
||||||
|
m_macAddr = macAddr;
|
||||||
|
m_maxMaster = maxMaster;
|
||||||
|
m_deviceInstanceID = deviceInstanceID;
|
||||||
|
|
||||||
|
// Let the fun begin...
|
||||||
|
|
||||||
|
// setup our info
|
||||||
|
Device_Set_Object_Instance_Number(m_deviceInstanceID);
|
||||||
|
address_init();
|
||||||
|
|
||||||
|
initServiceHandlers();
|
||||||
|
|
||||||
|
dlmstp_set_max_info_frames(m_maxInfoFrames);
|
||||||
|
dlmstp_set_max_master(m_maxMaster);
|
||||||
|
dlmstp_set_baud_rate(m_baudRate);
|
||||||
|
dlmstp_set_mac_address(m_macAddr);
|
||||||
|
|
||||||
|
// FIXME - allow to change?
|
||||||
|
apdu_timeout_set(m_adpuTimeoutMS);
|
||||||
|
|
||||||
|
// Ordinarily, I'd like to check the return value of this function,
|
||||||
|
// but even in the face of errors, it always returns true :( This
|
||||||
|
// function starts the ball rolling, and initializes the Master FSM
|
||||||
|
// thread. Unfortunately, it doesn't appear this can be turned back
|
||||||
|
// off without exiting the application.
|
||||||
|
datalink_init((char *)port.c_str());
|
||||||
|
|
||||||
|
m_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BACNETMSTP::dispatchRequest()
|
||||||
|
{
|
||||||
|
uint16_t pdu_len = 0;
|
||||||
|
unsigned timeout = 100; // milliseconds
|
||||||
|
unsigned max_apdu = 0;
|
||||||
|
time_t elapsed_seconds = 0;
|
||||||
|
time_t last_seconds = 0;
|
||||||
|
time_t current_seconds = 0;
|
||||||
|
time_t timeout_seconds = 0;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
// address where message came from
|
||||||
|
BACNET_ADDRESS src = {0};
|
||||||
|
|
||||||
|
clearErrors();
|
||||||
|
m_errorDetected = false;
|
||||||
|
|
||||||
|
uint32_t targetDeviceInstanceID = BACNET_MAX_INSTANCE;
|
||||||
|
|
||||||
|
switch (m_command.cmd)
|
||||||
|
{
|
||||||
|
case BACCMD_READ_PROPERTY:
|
||||||
|
targetDeviceInstanceID = m_command.readPropArgs.targetDeviceInstanceID;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACCMD_WRITE_PROPERTY:
|
||||||
|
targetDeviceInstanceID = m_command.writePropArgs.targetDeviceInstanceID;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACCMD_NONE:
|
||||||
|
{
|
||||||
|
m_errorType = BACERR_TYPE_UPM;
|
||||||
|
m_upmErrorString = string(__FUNCTION__) +
|
||||||
|
": called with BACCMD_NONE, ignoring";
|
||||||
|
|
||||||
|
return true; // error
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// should this throw?
|
||||||
|
m_errorType = BACERR_TYPE_UPM;
|
||||||
|
m_upmErrorString = string(__FUNCTION__) +
|
||||||
|
": internal error, called with unknown command, ignoring";
|
||||||
|
|
||||||
|
return true; // error
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// timeouts
|
||||||
|
last_seconds = time(NULL);
|
||||||
|
timeout_seconds = (apdu_timeout() / 1000) * apdu_retries();
|
||||||
|
|
||||||
|
// we use 0 to indicate that request hasn't been made yet, so that
|
||||||
|
// it will be made once the address is bound.
|
||||||
|
m_invokeID = 0;
|
||||||
|
|
||||||
|
// bind to the device first.
|
||||||
|
found = address_bind_request(targetDeviceInstanceID, &max_apdu,
|
||||||
|
&(instance()->m_targetAddress));
|
||||||
|
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": Address not found, Sending WhoIs..." << endl;
|
||||||
|
|
||||||
|
Send_WhoIs(targetDeviceInstanceID, targetDeviceInstanceID);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": Address was found" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// loop until either we get our data, an error occurs, or we timeout
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
current_seconds = time(NULL);
|
||||||
|
|
||||||
|
// at least one second has passed
|
||||||
|
if (current_seconds != last_seconds)
|
||||||
|
tsm_timer_milliseconds((uint16_t) ((current_seconds -
|
||||||
|
last_seconds) * 1000));
|
||||||
|
if (m_errorDetected)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// we have to wait until the address is bound before proceeding
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
found =
|
||||||
|
address_bind_request(targetDeviceInstanceID, &max_apdu,
|
||||||
|
&(instance()->m_targetAddress));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found)
|
||||||
|
{
|
||||||
|
// address is bound, and we have not sent our request yet. Make it so.
|
||||||
|
if (m_invokeID == 0)
|
||||||
|
{
|
||||||
|
switch (m_command.cmd)
|
||||||
|
{
|
||||||
|
case BACCMD_READ_PROPERTY:
|
||||||
|
m_invokeID =
|
||||||
|
Send_Read_Property_Request(targetDeviceInstanceID,
|
||||||
|
m_command.readPropArgs.objType,
|
||||||
|
m_command.readPropArgs.objInstance,
|
||||||
|
m_command.readPropArgs.objProperty,
|
||||||
|
m_command.readPropArgs.arrayIndex);
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__
|
||||||
|
<< ": Called Send_Read_Property_Request(), m_invokeID = "
|
||||||
|
<< (int)m_invokeID << endl;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACCMD_WRITE_PROPERTY:
|
||||||
|
m_invokeID =
|
||||||
|
Send_Write_Property_Request(targetDeviceInstanceID,
|
||||||
|
m_command.writePropArgs.objType,
|
||||||
|
m_command.writePropArgs.objInstance,
|
||||||
|
m_command.writePropArgs.objProperty,
|
||||||
|
m_command.writePropArgs.propValue,
|
||||||
|
m_command.writePropArgs.propPriority,
|
||||||
|
m_command.writePropArgs.arrayIndex);
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__
|
||||||
|
<< ": Called Send_Write_Property_Request(), m_invokeID = "
|
||||||
|
<< (int)m_invokeID << endl;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (tsm_invoke_id_free(m_invokeID))
|
||||||
|
{
|
||||||
|
// transaction completed successfully
|
||||||
|
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": Success, m_invokeID = "
|
||||||
|
<< (int)m_invokeID << endl;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (tsm_invoke_id_failed(m_invokeID))
|
||||||
|
{
|
||||||
|
// transaction state machine failed, most likely timeout
|
||||||
|
tsm_free_invoke_id(m_invokeID);
|
||||||
|
|
||||||
|
m_errorType = BACERR_TYPE_UPM;
|
||||||
|
m_upmErrorString = string(__FUNCTION__) +
|
||||||
|
": TSM Timed Out.";
|
||||||
|
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << m_upmErrorString << endl;
|
||||||
|
|
||||||
|
m_errorDetected = true;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// still waiting to bind. timeout if we've waited too long.
|
||||||
|
elapsed_seconds += (current_seconds - last_seconds);
|
||||||
|
if (elapsed_seconds > timeout_seconds)
|
||||||
|
{
|
||||||
|
m_errorType = BACERR_TYPE_UPM;
|
||||||
|
m_upmErrorString = string(__FUNCTION__) +
|
||||||
|
": Timed out waiting to bind address.";
|
||||||
|
|
||||||
|
// We output this error unconditionally as this is an
|
||||||
|
// error you will get if you supply a non-existant
|
||||||
|
// Device Obeject Instance ID.
|
||||||
|
|
||||||
|
cerr << m_upmErrorString << endl;
|
||||||
|
cerr << __FUNCTION__
|
||||||
|
<< ": Did you supply the correct Device Object Instance ID "
|
||||||
|
<< "for your device?"
|
||||||
|
<< endl;
|
||||||
|
|
||||||
|
m_errorDetected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns 0 bytes on timeout
|
||||||
|
pdu_len = datalink_receive(&src, m_rxBuffer, MAX_MPDU, timeout);
|
||||||
|
|
||||||
|
// process the packet if valid. This will call our handlers as needed.
|
||||||
|
if (pdu_len)
|
||||||
|
npdu_handler(&src, m_rxBuffer, pdu_len);
|
||||||
|
|
||||||
|
// keep track of time for next check
|
||||||
|
last_seconds = current_seconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_errorDetected;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BACNETMSTP::readProperty(uint32_t targetDeviceInstanceID,
|
||||||
|
BACNET_OBJECT_TYPE objType,
|
||||||
|
uint32_t objInstance,
|
||||||
|
BACNET_PROPERTY_ID objProperty,
|
||||||
|
uint32_t arrayIndex)
|
||||||
|
{
|
||||||
|
// some sanity checking...
|
||||||
|
if (objInstance >= BACNET_MAX_INSTANCE)
|
||||||
|
{
|
||||||
|
throw std::out_of_range(std::string(__FUNCTION__)
|
||||||
|
+ ": objInstance must be less than "
|
||||||
|
+ std::to_string(BACNET_MAX_INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill in the command structure and dispatch
|
||||||
|
m_command.cmd = BACCMD_READ_PROPERTY;
|
||||||
|
m_command.readPropArgs.targetDeviceInstanceID = targetDeviceInstanceID;
|
||||||
|
m_command.readPropArgs.objType = objType;
|
||||||
|
m_command.readPropArgs.objInstance = objInstance;
|
||||||
|
m_command.readPropArgs.objProperty = objProperty;
|
||||||
|
m_command.readPropArgs.arrayIndex = arrayIndex; // not implemented in the ack handler!
|
||||||
|
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": calling dispatchRequest()..." << endl;
|
||||||
|
|
||||||
|
// send it off
|
||||||
|
bool error = dispatchRequest();
|
||||||
|
|
||||||
|
// clear the command to avoid accidental re-calls
|
||||||
|
m_command.cmd = BACCMD_NONE;
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BACNETMSTP::writeProperty(uint32_t targetDeviceInstanceID,
|
||||||
|
BACNET_OBJECT_TYPE objType,
|
||||||
|
uint32_t objInstance,
|
||||||
|
BACNET_PROPERTY_ID objProperty,
|
||||||
|
BACNET_APPLICATION_DATA_VALUE* propValue,
|
||||||
|
uint8_t propPriority,
|
||||||
|
int32_t arrayIndex)
|
||||||
|
{
|
||||||
|
// some sanity checking...
|
||||||
|
if (objInstance >= BACNET_MAX_INSTANCE)
|
||||||
|
{
|
||||||
|
throw std::out_of_range(std::string(__FUNCTION__)
|
||||||
|
+ ": objInstance must be less than "
|
||||||
|
+ std::to_string(BACNET_MAX_INSTANCE));
|
||||||
|
}
|
||||||
|
|
||||||
|
// fill in the command structure and dispatch
|
||||||
|
m_command.cmd = BACCMD_WRITE_PROPERTY;
|
||||||
|
m_command.writePropArgs.targetDeviceInstanceID = targetDeviceInstanceID;
|
||||||
|
m_command.writePropArgs.objType = objType;
|
||||||
|
m_command.writePropArgs.objInstance = objInstance;
|
||||||
|
m_command.writePropArgs.objProperty = objProperty;
|
||||||
|
m_command.writePropArgs.propValue = propValue;
|
||||||
|
m_command.writePropArgs.propPriority = propPriority;
|
||||||
|
m_command.writePropArgs.arrayIndex = arrayIndex; // not implemented!
|
||||||
|
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": calling dispatchRequest()..." << endl;
|
||||||
|
|
||||||
|
// send it off
|
||||||
|
bool error = dispatchRequest();
|
||||||
|
|
||||||
|
// clear the command to avoid accidental re-calls
|
||||||
|
m_command.cmd = BACCMD_NONE;
|
||||||
|
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::getData()
|
||||||
|
{
|
||||||
|
return m_returnedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t BACNETMSTP::getDataType()
|
||||||
|
{
|
||||||
|
return m_returnedValue.tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
float BACNETMSTP::getDataTypeReal()
|
||||||
|
{
|
||||||
|
if (getDataType() == BACNET_APPLICATION_TAG_REAL)
|
||||||
|
return m_returnedValue.type.Real;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": Not of Real type, trying to convert..." << endl;
|
||||||
|
|
||||||
|
// try to convert or throw
|
||||||
|
switch (getDataType())
|
||||||
|
{
|
||||||
|
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||||
|
return (getDataTypeBoolean() ? 1.0 : 0.0);
|
||||||
|
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||||
|
return float(getDataTypeUnsignedInt());
|
||||||
|
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||||
|
return float(getDataTypeSignedInt());
|
||||||
|
default:
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to Real");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BACNETMSTP::getDataTypeBoolean()
|
||||||
|
{
|
||||||
|
if (getDataType() == BACNET_APPLICATION_TAG_BOOLEAN)
|
||||||
|
return ((m_returnedValue.type.Boolean) ? true : false);
|
||||||
|
else
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to Bool");
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int BACNETMSTP::getDataTypeUnsignedInt()
|
||||||
|
{
|
||||||
|
if (getDataType() == BACNET_APPLICATION_TAG_UNSIGNED_INT)
|
||||||
|
return m_returnedValue.type.Unsigned_Int;
|
||||||
|
else
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to UnsignedInt");
|
||||||
|
}
|
||||||
|
|
||||||
|
int BACNETMSTP::getDataTypeSignedInt()
|
||||||
|
{
|
||||||
|
if (getDataType() == BACNET_APPLICATION_TAG_SIGNED_INT)
|
||||||
|
return m_returnedValue.type.Signed_Int;
|
||||||
|
else
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to SignedInt");
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(BACAPP_DOUBLE)
|
||||||
|
double BACNETMSTP::getDataTypeDouble()
|
||||||
|
{
|
||||||
|
if (getDataType() == BACNET_APPLICATION_TAG_DOUBLE)
|
||||||
|
return m_returnedValue.type.Double;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_debugging)
|
||||||
|
cerr << __FUNCTION__ << ": Not of Double type, trying to convert..." << endl;
|
||||||
|
|
||||||
|
// try to convert or throw
|
||||||
|
switch (getDataType())
|
||||||
|
{
|
||||||
|
case BACNET_APPLICATION_TAG_REAL:
|
||||||
|
return double(getDataTypeReal());
|
||||||
|
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||||
|
return (getDataTypeBoolean() ? 1.0 : 0.0);
|
||||||
|
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||||
|
return double(getDataTypeUnsignedInt());
|
||||||
|
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||||
|
return double(getDataTypeSignedInt());
|
||||||
|
default:
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to Double");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // BACAPP_DOUBLE
|
||||||
|
|
||||||
|
unsigned int BACNETMSTP::getDataTypeEnum()
|
||||||
|
{
|
||||||
|
if (getDataType() == BACNET_APPLICATION_TAG_ENUMERATED)
|
||||||
|
return m_returnedValue.type.Enumerated;
|
||||||
|
else
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to Enum");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string BACNETMSTP::getDataTypeString()
|
||||||
|
{
|
||||||
|
string retval;
|
||||||
|
|
||||||
|
// Here, we can try to accomodate all the types
|
||||||
|
switch(getDataType())
|
||||||
|
{
|
||||||
|
case BACNET_APPLICATION_TAG_REAL:
|
||||||
|
retval = std::to_string(getDataTypeReal());
|
||||||
|
break;
|
||||||
|
|
||||||
|
#if defined(BACAPP_DOUBLE)
|
||||||
|
case BACNET_APPLICATION_TAG_DOUBLE:
|
||||||
|
retval = std::to_string(getDataTypeDouble());
|
||||||
|
break;
|
||||||
|
#endif // BACAPP_DOUBLE
|
||||||
|
|
||||||
|
case BACNET_APPLICATION_TAG_UNSIGNED_INT:
|
||||||
|
retval = std::to_string(getDataTypeUnsignedInt());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACNET_APPLICATION_TAG_SIGNED_INT:
|
||||||
|
retval = std::to_string(getDataTypeSignedInt());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACNET_APPLICATION_TAG_BOOLEAN:
|
||||||
|
retval = (getDataTypeBoolean() ? string("true") : string("false"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACNET_APPLICATION_TAG_CHARACTER_STRING:
|
||||||
|
retval = string(characterstring_value(&m_returnedValue.type.Character_String),
|
||||||
|
|
||||||
|
characterstring_length(&m_returnedValue.type.Character_String));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACNET_APPLICATION_TAG_OCTET_STRING:
|
||||||
|
{
|
||||||
|
string tmpstr((char *)octetstring_value(&m_returnedValue.type.Octet_String),
|
||||||
|
|
||||||
|
octetstring_length(&m_returnedValue.type.Octet_String));
|
||||||
|
retval = string2HexString(tmpstr);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BACNET_APPLICATION_TAG_BIT_STRING:
|
||||||
|
{
|
||||||
|
int len = bitstring_bits_used(&m_returnedValue.type.Bit_String);
|
||||||
|
|
||||||
|
for (int i=0; i<len; i++)
|
||||||
|
{
|
||||||
|
if (bitstring_bit(&m_returnedValue.type.Bit_String, uint8_t(i)))
|
||||||
|
retval += "1";
|
||||||
|
else
|
||||||
|
retval += "0";
|
||||||
|
|
||||||
|
if (i != 0 && ((i % 8) == 0))
|
||||||
|
retval += " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": data type ("
|
||||||
|
+ std::to_string(int(getDataType()))
|
||||||
|
+ ") is not convertible to String");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataReal(float value)
|
||||||
|
{
|
||||||
|
BACNET_APPLICATION_DATA_VALUE data;
|
||||||
|
|
||||||
|
memset(&data, 0, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||||
|
|
||||||
|
data.tag = BACNET_APPLICATION_TAG_REAL;
|
||||||
|
data.type.Real = value;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataBool(bool value)
|
||||||
|
{
|
||||||
|
BACNET_APPLICATION_DATA_VALUE data;
|
||||||
|
|
||||||
|
memset(&data, 0, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||||
|
|
||||||
|
data.tag = BACNET_APPLICATION_TAG_BOOLEAN;
|
||||||
|
data.type.Boolean = value;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataSignedInt(int value)
|
||||||
|
{
|
||||||
|
BACNET_APPLICATION_DATA_VALUE data;
|
||||||
|
|
||||||
|
memset(&data, 0, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||||
|
|
||||||
|
data.tag = BACNET_APPLICATION_TAG_SIGNED_INT;
|
||||||
|
data.type.Signed_Int = value;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataUnsignedInt(unsigned int value)
|
||||||
|
{
|
||||||
|
BACNET_APPLICATION_DATA_VALUE data;
|
||||||
|
|
||||||
|
memset(&data, 0, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||||
|
|
||||||
|
data.tag = BACNET_APPLICATION_TAG_UNSIGNED_INT;
|
||||||
|
data.type.Unsigned_Int = value;
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE BACNETMSTP::createDataString(string value)
|
||||||
|
{
|
||||||
|
if (value.size() > (MAX_CHARACTER_STRING_BYTES - 1))
|
||||||
|
{
|
||||||
|
throw std::invalid_argument(std::string(__FUNCTION__)
|
||||||
|
+ ": value must be less than or equal to "
|
||||||
|
+ std::to_string(MAX_CHARACTER_STRING_BYTES - 1)
|
||||||
|
+ " characters long");
|
||||||
|
}
|
||||||
|
|
||||||
|
BACNET_APPLICATION_DATA_VALUE data;
|
||||||
|
|
||||||
|
memset(&data, 0, sizeof(BACNET_APPLICATION_DATA_VALUE));
|
||||||
|
|
||||||
|
data.tag = BACNET_APPLICATION_TAG_CHARACTER_STRING;
|
||||||
|
|
||||||
|
characterstring_init_ansi(&data.type.Character_String, value.c_str());
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string BACNETMSTP::string2HexString(string input)
|
||||||
|
{
|
||||||
|
static const char* const lut = "0123456789abcdef";
|
||||||
|
size_t len = input.size();
|
||||||
|
|
||||||
|
string output;
|
||||||
|
output.reserve(3 * len);
|
||||||
|
for (size_t i = 0; i < len; ++i)
|
||||||
|
{
|
||||||
|
const unsigned char c = input[i];
|
||||||
|
output.push_back(lut[c >> 4]);
|
||||||
|
output.push_back(lut[c & 15]);
|
||||||
|
output.push_back(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
716
src/bacnetmstp/bacnetmstp.h
Normal file
716
src/bacnetmstp/bacnetmstp.h
Normal file
@ -0,0 +1,716 @@
|
|||||||
|
/*
|
||||||
|
* Author: Jon Trulson <jtrulson@ics.com>
|
||||||
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||||
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||||
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||||
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// we only support a BACnet RS-485 MS/TP datalink
|
||||||
|
#define BACDL_MSTP 1
|
||||||
|
#undef BACDL_ALL
|
||||||
|
|
||||||
|
// get a variety of bacnet-stack includes...
|
||||||
|
#include "bacdef.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "bactext.h"
|
||||||
|
#include "bacerror.h"
|
||||||
|
#include "iam.h"
|
||||||
|
#include "arf.h"
|
||||||
|
#include "tsm.h"
|
||||||
|
#include "address.h"
|
||||||
|
#include "npdu.h"
|
||||||
|
#include "apdu.h"
|
||||||
|
#include "device.h"
|
||||||
|
#include "datalink.h"
|
||||||
|
#include "whois.h"
|
||||||
|
#include "mstpdef.h"
|
||||||
|
#include "dlmstp.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace upm {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief BACNETMSTP base class
|
||||||
|
* @defgroup bacnetmstp libupm-bacnetmstp
|
||||||
|
* @ingroup uart
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @library bacnetmstp
|
||||||
|
* @sensor bacnetmstp
|
||||||
|
* @comname UPM API for BACNET MS/TP communications
|
||||||
|
* @con uart
|
||||||
|
* @web http://bacnet.sourceforge.net/
|
||||||
|
* @brief UPM API for BACNETMSTP
|
||||||
|
*
|
||||||
|
* This is a singleton class that provides services to UPM BACnet
|
||||||
|
* drivers (like E50HX) based on the bacnet-stack at
|
||||||
|
* http://bacnet.sourceforge.net . This class is implemented as a
|
||||||
|
* singleton due to the fact that the bacnet-stack implementation
|
||||||
|
* does not currently allow multiple simultaneous datalinks. We are
|
||||||
|
* using 0.8.3 of bacnet-stack. In the future this restriction may
|
||||||
|
* be lifted depending on bacnet-stack, but for now, you are
|
||||||
|
* stuck with only a single BACnet MS/TP datalink.
|
||||||
|
*
|
||||||
|
* This driver is not intended to be used by end users. It is
|
||||||
|
* intended for use with other UPM drivers that require access to a
|
||||||
|
* BACnet MS/TP (Master Slave/Token Passing) network over RS-485.
|
||||||
|
*
|
||||||
|
* For this reason, no examples are provided. If you wish to
|
||||||
|
* implement your own BACnet MS/TP driver, please look at the E50HX
|
||||||
|
* driver to see how this class can be used.
|
||||||
|
*
|
||||||
|
* Currently, only readProperty and writeProperty BACnet requests
|
||||||
|
* are supported. In the future, any other BACnet requests could be
|
||||||
|
* supported as well. readProperty and writeProperty should provide
|
||||||
|
* most of what you will need when communicating with BACnet
|
||||||
|
* devices. Since the source code is open, feel free to add other
|
||||||
|
* services as you see fit :)
|
||||||
|
*
|
||||||
|
* In order to make requests over an MS/TP network, you must be a
|
||||||
|
* BACnet master. initMaster() is responsible for configuring your
|
||||||
|
* underlying RS-485 network and starting a Master FSM (finite state
|
||||||
|
* machine) thread that will be responsible for identifying other
|
||||||
|
* Masters on the network and negotiating token passing. Your
|
||||||
|
* master can only transmit when it has the token.
|
||||||
|
*
|
||||||
|
* Fortunately, all of these messy details are handled for you by
|
||||||
|
* this class, or the underlying bacnet-stack library this class
|
||||||
|
* relies on.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class BACNETMSTP {
|
||||||
|
// Constructor and destructor are protected
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// error types
|
||||||
|
typedef enum {
|
||||||
|
BACERR_TYPE_NONE = 0,
|
||||||
|
BACERR_TYPE_REJECT,
|
||||||
|
BACERR_TYPE_ABORT,
|
||||||
|
BACERR_TYPE_ERROR,
|
||||||
|
BACERR_TYPE_UPM
|
||||||
|
} BACERR_TYPE_T;
|
||||||
|
|
||||||
|
// command types we currently support
|
||||||
|
typedef enum {
|
||||||
|
BACCMD_NONE = 0,
|
||||||
|
BACCMD_READ_PROPERTY,
|
||||||
|
BACCMD_WRITE_PROPERTY
|
||||||
|
} BACCMD_TYPE_T;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get our singleton instance, initializing it if neccessary. All
|
||||||
|
* requests to this class should be done through this instance
|
||||||
|
* accessor.
|
||||||
|
*
|
||||||
|
* @return static pointer to our class instance
|
||||||
|
*/
|
||||||
|
static BACNETMSTP* instance();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function initializes the underlying BACNETMSTP Master
|
||||||
|
* singleton in the event it has not already been initialized. If
|
||||||
|
* the BACNETMSTP Master singleton has already been initialized,
|
||||||
|
* then this call will be ignored. There can be only one.
|
||||||
|
*
|
||||||
|
* @param port The serial port that the RS-485 interface is
|
||||||
|
* connected to.
|
||||||
|
* @param baudRate The baudrate of the RS-485 interface. All
|
||||||
|
* devices on a BACnet RS-485 bus must run at the same baudrate.
|
||||||
|
* Valid values are 9600, 19200, 38400, 57600, 76800, and 115200.
|
||||||
|
* @param deviceInstanceNumber This is the unique Device Object
|
||||||
|
* Instance number that will be used for our BACnet Master in
|
||||||
|
* order to communicate over the BACnet interface. This number
|
||||||
|
* must be between 1-4194302 and must be unique on the BACnet
|
||||||
|
* network.
|
||||||
|
* @param macAddr This is the MAC address of our BACnet Master.
|
||||||
|
* It must be unique on the BACnet segment, and must be between
|
||||||
|
* 1-127.
|
||||||
|
* @param maxMaster This specifies to our Master the maximum MAC
|
||||||
|
* address used by any other Masters on the BACnet network. This
|
||||||
|
* must be between 1-127, the default is 127. Do not change this
|
||||||
|
* unless you know what you are doing or you could introduce
|
||||||
|
* token passing errors on the BACnet network.
|
||||||
|
* @param maxInfoFrames This number specifies the maximum number
|
||||||
|
* of transmissions (like requests for data) our Master is allowed
|
||||||
|
* to make before passing the token to the next Master. The
|
||||||
|
* default is 1.
|
||||||
|
*/
|
||||||
|
void initMaster(std::string port, int baudRate, int deviceInstanceNumber,
|
||||||
|
int macAddr, int maxMaster=DEFAULT_MAX_MASTER,
|
||||||
|
int maxInfoFrames=1);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a BACnet readProperty transaction. This function will
|
||||||
|
* return when either the transaction has completed, or an error
|
||||||
|
* has occurred. It requests the value of a property, belonging
|
||||||
|
* to a specific object instance on a specific device.
|
||||||
|
*
|
||||||
|
* @param targetDeviceInstanceID This is the Device Object
|
||||||
|
* Instance ID of the device to send the request to. This number
|
||||||
|
* will be unique for every device on the network. An address
|
||||||
|
* lookup will be performed the first time a request is made to a
|
||||||
|
* device using the WhoHas BACnet service. The result will be
|
||||||
|
* cached for further use.
|
||||||
|
* @param objType This is the BACnet object type of the object you
|
||||||
|
* wish to query. It should be one of the BACNET_OBJECT_TYPE
|
||||||
|
* values.
|
||||||
|
* @param objInstance This is the instance number of the Object
|
||||||
|
* you wish to access. It is an integer starting from 1.
|
||||||
|
* @param objProperty This is the property of the Object and
|
||||||
|
* instance you wish to access. It should be one of the
|
||||||
|
* BACNET_PROPERTY_ID values.
|
||||||
|
* @param arrayIndex This specifies the index number of an array
|
||||||
|
* property. This is not currently supported. Until it is, leave
|
||||||
|
* the default at BACNET_ARRAY_ALL.
|
||||||
|
* @return true if an error occurred, false otherwise.
|
||||||
|
*/
|
||||||
|
bool readProperty(uint32_t targetDeviceInstanceID,
|
||||||
|
BACNET_OBJECT_TYPE objType,
|
||||||
|
uint32_t objInstance,
|
||||||
|
BACNET_PROPERTY_ID objProperty,
|
||||||
|
uint32_t arrayIndex=BACNET_ARRAY_ALL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a BACnet writeProperty transaction. This function will
|
||||||
|
* return when either the transaction has completed, or an error
|
||||||
|
* has occurred. It writes the supplied value to a property,
|
||||||
|
* belonging to a specific object instance on a specific device.
|
||||||
|
*
|
||||||
|
* @param targetDeviceInstanceID This is the Device Object
|
||||||
|
* Instance ID of the device to send the request to. This number
|
||||||
|
* will be unique for every device on the network. An address
|
||||||
|
* lookup will be performed the first time a request is made to a
|
||||||
|
* device using the WhoHas BACnet service. The result will be
|
||||||
|
* cached for further use.
|
||||||
|
* @param objType This is the BACnet object type of the object you
|
||||||
|
* wish to query. It should be one of the BACNET_OBJECT_TYPE
|
||||||
|
* values.
|
||||||
|
* @param objInstance This is the instance number of the Object
|
||||||
|
* you wish to access. It is an integer starting from 1.
|
||||||
|
* @param objProperty This is the property of the Object and
|
||||||
|
* instance you wish to access. It should be one of the
|
||||||
|
* BACNET_PROPERTY_ID values.
|
||||||
|
* @param propValue This is a pointer to a
|
||||||
|
* BACNET_APPLICATION_DATA_VALUE structure containg the data value
|
||||||
|
* to write to the property. Use the createData*() methods to
|
||||||
|
* properly create these structures.
|
||||||
|
* @param propPriority This specifies the priority of a
|
||||||
|
* commandable property. Leave it at the default unless you know
|
||||||
|
* what you are doing. In addition, there is conflicting
|
||||||
|
* information in the bacnet-stack documentation as to whether
|
||||||
|
* this is even supported.
|
||||||
|
* @param arrayIndex This specifies the index number of an array
|
||||||
|
* property. This is not currently supported. Until it is, leave
|
||||||
|
* the default at BACNET_ARRAY_ALL.
|
||||||
|
* @return true if an error occurred, false otherwise.
|
||||||
|
*/
|
||||||
|
bool writeProperty(uint32_t targetDeviceInstanceID,
|
||||||
|
BACNET_OBJECT_TYPE objType,
|
||||||
|
uint32_t objInstance,
|
||||||
|
BACNET_PROPERTY_ID objProperty,
|
||||||
|
BACNET_APPLICATION_DATA_VALUE* propValue,
|
||||||
|
uint8_t propPriority=BACNET_NO_PRIORITY,
|
||||||
|
int32_t arrayIndex=BACNET_ARRAY_ALL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be used
|
||||||
|
* to return a BACNET_APPLICATION_DATA_VALUE structure containing
|
||||||
|
* the returned data.
|
||||||
|
*
|
||||||
|
* @return a BACNET_APPLICATION_DATA_VALUE structure containing
|
||||||
|
* the returned data.
|
||||||
|
*/
|
||||||
|
BACNET_APPLICATION_DATA_VALUE getData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet data type of the returned data. It
|
||||||
|
* will be one of the BACNET_APPLICATION_TAG_* values.
|
||||||
|
*
|
||||||
|
* @return A BACNET_APPLICATION_TAG_* value
|
||||||
|
*/
|
||||||
|
uint8_t getDataType();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as a
|
||||||
|
* Real. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_REAL, and the value returned cannot be
|
||||||
|
* safely converted, an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return A floating point value representing the returned data
|
||||||
|
*/
|
||||||
|
float getDataTypeReal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as a
|
||||||
|
* Boolean. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_BOOLEAN, and the value returned cannot
|
||||||
|
* be safely converted, an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return A boolean value representing the returned data
|
||||||
|
*/
|
||||||
|
bool getDataTypeBoolean();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as a
|
||||||
|
* unsigned int. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_UNSIGNED_INT, and the value returned
|
||||||
|
* cannot be safely converted, an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return An unsigned int value representing the returned data
|
||||||
|
*/
|
||||||
|
unsigned int getDataTypeUnsignedInt();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as a
|
||||||
|
* signed int. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_SIGNED_INT, and the value returned
|
||||||
|
* cannot be safely converted, an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return A signed int value representing the returned data
|
||||||
|
*/
|
||||||
|
int getDataTypeSignedInt();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as a
|
||||||
|
* string. Most of the data types except Enum can be converted to
|
||||||
|
* a string. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_CHARACTER_STRING, and the value returned
|
||||||
|
* cannot be safely converted, an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return A string value representing the returned data
|
||||||
|
*/
|
||||||
|
std::string getDataTypeString();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as an
|
||||||
|
* enumeration. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_ENUMERATED an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return An unsigned int representing a BACnet enumerant
|
||||||
|
*/
|
||||||
|
unsigned int getDataTypeEnum();
|
||||||
|
|
||||||
|
#if defined(BACAPP_DOUBLE)
|
||||||
|
/**
|
||||||
|
* After a successful readProperty request, this method can be
|
||||||
|
* used to return the BACnet dataype of the returned data as a
|
||||||
|
* double. If the data type (getDataType()) is not a
|
||||||
|
* BACNET_APPLICATION_TAG_DOUBLE, and the value returned cannot be
|
||||||
|
* safely converted, an exception is thrown.
|
||||||
|
*
|
||||||
|
* @return A double floating point value representing the returned data
|
||||||
|
*/
|
||||||
|
double getDataTypeDouble();
|
||||||
|
#endif // BACAPP_DOUBLE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create and return an initialized
|
||||||
|
* BACNET_APPLICATION_DATA_VALUE containing a real (floating point
|
||||||
|
* value). A pointer to this returned structure can then be used
|
||||||
|
* with writeProperty().
|
||||||
|
*
|
||||||
|
* @param value The floating point value to initialize the structure to.
|
||||||
|
* @return An initialized structure containing the value
|
||||||
|
*/
|
||||||
|
BACNET_APPLICATION_DATA_VALUE createDataReal(float Real);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create and return an initialized
|
||||||
|
* BACNET_APPLICATION_DATA_VALUE containing a boolean. A pointer
|
||||||
|
* to this returned structure can then be used with
|
||||||
|
* writeProperty().
|
||||||
|
*
|
||||||
|
* @param value The boolean value to initialize the structure to.
|
||||||
|
* @return An initialized structure containing the value
|
||||||
|
*/
|
||||||
|
BACNET_APPLICATION_DATA_VALUE createDataBool(bool value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create and return an initialized
|
||||||
|
* BACNET_APPLICATION_DATA_VALUE containing a signed integer. A
|
||||||
|
* pointer to this returned structure can then be used with
|
||||||
|
* writeProperty().
|
||||||
|
*
|
||||||
|
* @param value The signed integer value to initialize the structure to.
|
||||||
|
* @return An initialized structure containing the value
|
||||||
|
*/
|
||||||
|
BACNET_APPLICATION_DATA_VALUE createDataSignedInt(int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create and return an initialized
|
||||||
|
* BACNET_APPLICATION_DATA_VALUE containing a unsigned integer. A
|
||||||
|
* pointer to this returned structure can then be used with
|
||||||
|
* writeProperty().
|
||||||
|
*
|
||||||
|
* @param value The unsigned integer value to initialize the
|
||||||
|
* structure to.
|
||||||
|
* @return An initialized structure containing the value
|
||||||
|
*/
|
||||||
|
BACNET_APPLICATION_DATA_VALUE createDataUnsignedInt(unsigned int value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to create and return an initialized
|
||||||
|
* BACNET_APPLICATION_DATA_VALUE containing a character string. A
|
||||||
|
* pointer to this returned structure can then be used with
|
||||||
|
* writeProperty(). Strings are typically limited to 63 characters.
|
||||||
|
*
|
||||||
|
* @param value The character string value to initialize the
|
||||||
|
* structure to.
|
||||||
|
* @return An initialized structure containing the value
|
||||||
|
*/
|
||||||
|
BACNET_APPLICATION_DATA_VALUE createDataString(std::string value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an enumration of the last error type to occur. The
|
||||||
|
* value returned will be one of the BACERR_TYPE_T values.
|
||||||
|
*
|
||||||
|
* @return The last error type to occur, one of the BACERR_TYPE_T
|
||||||
|
* values.
|
||||||
|
*/
|
||||||
|
BACERR_TYPE_T getErrorType()
|
||||||
|
{
|
||||||
|
return m_errorType;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a BACnet Reject error, return the error code.
|
||||||
|
*
|
||||||
|
* @return The Reject error code.
|
||||||
|
*/
|
||||||
|
uint8_t getRejectReason()
|
||||||
|
{
|
||||||
|
return m_rejectReason;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a BACnet Reject error, return the error string.
|
||||||
|
*
|
||||||
|
* @return The Reject error string.
|
||||||
|
*/
|
||||||
|
std::string getRejectString()
|
||||||
|
{
|
||||||
|
return m_rejectString;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a BACnet Abort error, return the Abort reason code.
|
||||||
|
*
|
||||||
|
* @return The Abort reason code.
|
||||||
|
*/
|
||||||
|
uint8_t getAbortReason()
|
||||||
|
{
|
||||||
|
return m_abortReason;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a BACnet Abort error, return the Abort string.
|
||||||
|
*
|
||||||
|
* @return The Abort error string.
|
||||||
|
*/
|
||||||
|
std::string getAbortString()
|
||||||
|
{
|
||||||
|
return m_abortString;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a general BACnet error, return the BACnet error class.
|
||||||
|
*
|
||||||
|
* @return One of the BACNET_ERROR_CLASS error class codes
|
||||||
|
*/
|
||||||
|
BACNET_ERROR_CLASS getErrorClass()
|
||||||
|
{
|
||||||
|
return m_errorClass;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a general BACnet error, return the BACnet error code.
|
||||||
|
*
|
||||||
|
* @return One of the BACNET_ERROR_CODE error codes
|
||||||
|
*/
|
||||||
|
BACNET_ERROR_CODE getErrorCode()
|
||||||
|
{
|
||||||
|
return m_errorCode;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a general BACnet error, return the BACnet error
|
||||||
|
* string.
|
||||||
|
*
|
||||||
|
* @return A string representing the BACnet error class and code.
|
||||||
|
*/
|
||||||
|
std::string getErrorString()
|
||||||
|
{
|
||||||
|
return m_errorString;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In the event of a non-BACnet UPM error, return a string
|
||||||
|
* describing the error.
|
||||||
|
*
|
||||||
|
* @return A string representing the UPM error.
|
||||||
|
*/
|
||||||
|
std::string getUPMErrorString()
|
||||||
|
{
|
||||||
|
return m_upmErrorString;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if initMaster) has already been called, and out
|
||||||
|
* master is initialized.
|
||||||
|
*
|
||||||
|
* @return true if the master is initialized, false otherwise
|
||||||
|
*/
|
||||||
|
bool isInitialized()
|
||||||
|
{
|
||||||
|
return m_initialized;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the port that was specified to initMaster().
|
||||||
|
*
|
||||||
|
* @return The port specified to initMaster().
|
||||||
|
*/
|
||||||
|
std::string getPort()
|
||||||
|
{
|
||||||
|
return m_port;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the Object Device Instance ID for our Master was
|
||||||
|
* specified to initMaster().
|
||||||
|
*
|
||||||
|
* @return The Object Device Instance ID for our Master.
|
||||||
|
*/
|
||||||
|
uint32_t getDeviceInstanceID()
|
||||||
|
{
|
||||||
|
return m_deviceInstanceID;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the maxInfoFrames parameter that was specified to initMaster().
|
||||||
|
*
|
||||||
|
* @return The maxInfoFrames parameter specified to initMaster().
|
||||||
|
*/
|
||||||
|
int getMaxInfoFrames()
|
||||||
|
{
|
||||||
|
return m_maxInfoFrames;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the maxMaster parameter that was specified to initMaster().
|
||||||
|
*
|
||||||
|
* @return The maxMaster parameter specified to initMaster().
|
||||||
|
*/
|
||||||
|
int getMaxMaster()
|
||||||
|
{
|
||||||
|
return m_maxMaster;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the baud rate parameter that was specified to initMaster().
|
||||||
|
*
|
||||||
|
* @return The baud rate parameter specified to initMaster().
|
||||||
|
*/
|
||||||
|
int getBaudRate()
|
||||||
|
{
|
||||||
|
return m_baudRate;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the MAC address parameter that was specified to initMaster().
|
||||||
|
*
|
||||||
|
* @return The MAC address parameter specified to initMaster().
|
||||||
|
*/
|
||||||
|
int getMACAddress()
|
||||||
|
{
|
||||||
|
return m_macAddr;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable debugging output.
|
||||||
|
*
|
||||||
|
* @param enable true to enable debugging, false otherwise
|
||||||
|
*/
|
||||||
|
void setDebug(bool enable);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
/**
|
||||||
|
* BACNETMSTP constructor
|
||||||
|
*/
|
||||||
|
BACNETMSTP();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* BACNETMSTP Destructor
|
||||||
|
*/
|
||||||
|
~BACNETMSTP();
|
||||||
|
|
||||||
|
// clear/reset error states
|
||||||
|
void clearErrors();
|
||||||
|
|
||||||
|
// error handler
|
||||||
|
static void handlerError(BACNET_ADDRESS * src,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
BACNET_ERROR_CLASS error_class,
|
||||||
|
BACNET_ERROR_CODE error_code);
|
||||||
|
|
||||||
|
// abort handler
|
||||||
|
static void handlerAbort(BACNET_ADDRESS * src,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
uint8_t abort_reason,
|
||||||
|
bool server);
|
||||||
|
|
||||||
|
// reject handler
|
||||||
|
static void handlerReject(BACNET_ADDRESS * src,
|
||||||
|
uint8_t invoke_id,
|
||||||
|
uint8_t reject_reason);
|
||||||
|
|
||||||
|
|
||||||
|
// our handler for dealing with return data from a ReadProperty call
|
||||||
|
static void handlerReadPropertyAck(uint8_t* service_request,
|
||||||
|
uint16_t service_len,
|
||||||
|
BACNET_ADDRESS* src,
|
||||||
|
BACNET_CONFIRMED_SERVICE_ACK_DATA* service_data);
|
||||||
|
|
||||||
|
// our handler for writeProp acks
|
||||||
|
static void handlerWritePropertyAck(BACNET_ADDRESS* src,
|
||||||
|
uint8_t invoke_id);
|
||||||
|
|
||||||
|
// initialize our service handlers
|
||||||
|
void initServiceHandlers();
|
||||||
|
|
||||||
|
// utility function
|
||||||
|
std::string string2HexString(std::string input);
|
||||||
|
|
||||||
|
// responsible for dispatching a request to the BACnet network
|
||||||
|
bool dispatchRequest();
|
||||||
|
|
||||||
|
private:
|
||||||
|
// prevent copying and assignment
|
||||||
|
BACNETMSTP(BACNETMSTP const &) {};
|
||||||
|
BACNETMSTP& operator=(BACNETMSTP const&) {};
|
||||||
|
|
||||||
|
// our class instance
|
||||||
|
static BACNETMSTP* m_instance;
|
||||||
|
|
||||||
|
// has the class been created yet?
|
||||||
|
bool m_initialized;
|
||||||
|
|
||||||
|
// Some items we can set for our master
|
||||||
|
std::string m_port;
|
||||||
|
int m_maxInfoFrames;
|
||||||
|
int m_maxMaster;
|
||||||
|
int m_baudRate;
|
||||||
|
int m_macAddr;
|
||||||
|
|
||||||
|
// the unique Instance Number of our Master Device Object
|
||||||
|
uint32_t m_deviceInstanceID;
|
||||||
|
|
||||||
|
// adpu timeout in milliseconds
|
||||||
|
uint16_t m_adpuTimeoutMS;
|
||||||
|
|
||||||
|
// buffer used for receiving data
|
||||||
|
uint8_t m_rxBuffer[MAX_MPDU];
|
||||||
|
|
||||||
|
// our error classfication
|
||||||
|
BACERR_TYPE_T m_errorType;
|
||||||
|
|
||||||
|
// BACnet reject info
|
||||||
|
uint8_t m_rejectReason;
|
||||||
|
std::string m_rejectString;
|
||||||
|
|
||||||
|
// BACnet abort info
|
||||||
|
uint8_t m_abortReason;
|
||||||
|
std::string m_abortString;
|
||||||
|
|
||||||
|
// BACnet error info
|
||||||
|
BACNET_ERROR_CLASS m_errorClass;
|
||||||
|
BACNET_ERROR_CODE m_errorCode;
|
||||||
|
std::string m_errorString;
|
||||||
|
|
||||||
|
// generic UPM related errors - we just set the error text to
|
||||||
|
// something informative.
|
||||||
|
std::string m_upmErrorString;
|
||||||
|
|
||||||
|
// our returned data from readProperty()
|
||||||
|
BACNET_APPLICATION_DATA_VALUE m_returnedValue;
|
||||||
|
|
||||||
|
// current bound target address of dispatched service request
|
||||||
|
// (read/write prop, etc)
|
||||||
|
BACNET_ADDRESS m_targetAddress;
|
||||||
|
|
||||||
|
// current invokeID (for transaction handling)
|
||||||
|
uint8_t m_invokeID;
|
||||||
|
|
||||||
|
// error detected flag
|
||||||
|
bool m_errorDetected;
|
||||||
|
|
||||||
|
// Commands - we create a struct to hold the arguments for each
|
||||||
|
// command type we support. Then, we create a command struct
|
||||||
|
// which contains the command type and a union containing the
|
||||||
|
// relevant arguments. This is used by dispatchRequest() to issue
|
||||||
|
// the correct request.
|
||||||
|
|
||||||
|
// these may generate SWIG warnings, but they can be ignored as we
|
||||||
|
// do not expose these outside the class
|
||||||
|
typedef struct {
|
||||||
|
uint32_t targetDeviceInstanceID;
|
||||||
|
BACNET_OBJECT_TYPE objType;
|
||||||
|
uint32_t objInstance;
|
||||||
|
BACNET_PROPERTY_ID objProperty;
|
||||||
|
uint32_t arrayIndex;
|
||||||
|
} READ_PROPERTY_ARGS_T;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t targetDeviceInstanceID;
|
||||||
|
BACNET_OBJECT_TYPE objType;
|
||||||
|
uint32_t objInstance;
|
||||||
|
BACNET_PROPERTY_ID objProperty;
|
||||||
|
BACNET_APPLICATION_DATA_VALUE* propValue;
|
||||||
|
uint8_t propPriority;
|
||||||
|
int32_t arrayIndex;
|
||||||
|
} WRITE_PROPERTY_ARGS_T;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
BACCMD_TYPE_T cmd;
|
||||||
|
|
||||||
|
union {
|
||||||
|
READ_PROPERTY_ARGS_T readPropArgs;
|
||||||
|
WRITE_PROPERTY_ARGS_T writePropArgs;
|
||||||
|
};
|
||||||
|
} m_command;
|
||||||
|
|
||||||
|
bool m_debugging;
|
||||||
|
};
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user