summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Morrow <joseph.l.morrow@intel.com>2015-03-10 14:53:51 -0400
committerErich Keane <erich.keane@intel.com>2015-03-11 23:01:13 +0000
commit58dd63b263db644913069498a1b203c113346a9d (patch)
tree2ae128ec00201fe2bba26ae37ec35ab704af6d15
parentec501972e17105287c868a34f452841f2ad1bb2a (diff)
downloadiotivity-58dd63b263db644913069498a1b203c113346a9d.tar.gz
iotivity-58dd63b263db644913069498a1b203c113346a9d.tar.bz2
iotivity-58dd63b263db644913069498a1b203c113346a9d.zip
Added SCons support for Arduino platform.
Change-Id: I9dcf69cef00dc14e099c1355ad7f2118746fa3e1 Signed-off-by: Doug Hudson <douglas.hudson@intel.com> Signed-off-by: Joseph Morrow <joseph.l.morrow@intel.com> Reviewed-on: https://gerrit.iotivity.org/gerrit/431 Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org> Reviewed-by: Erich Keane <erich.keane@intel.com>
-rw-r--r--.gitignore5
-rw-r--r--Readme.scons.txt2
-rw-r--r--arduino.scons18
-rwxr-xr-xauto_build.sh2
-rw-r--r--build_common/arduino/SConscript28
-rw-r--r--extlibs/arduino/SConscript148
-rw-r--r--resource/csdk/connectivity/common/SConscript3
-rw-r--r--resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript16
-rw-r--r--resource/csdk/stack/samples/linux/SimpleClientServer/SConscript1
9 files changed, 206 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore
index aec3a0b25..7c9c8ba68 100644
--- a/.gitignore
+++ b/.gitignore
@@ -55,3 +55,8 @@ platform
# Ignore downloaded dependencies
extlibs/gtest*
extlibs/cereal
+extlibs/hippomocks-master
+*.tgz
+*.zip
+extlibs/arduino/arduino-1.5.8
+build_common/arduino/extlibs/arduino/arduino-1.5.8
diff --git a/Readme.scons.txt b/Readme.scons.txt
index 27f89ce26..34abbfff9 100644
--- a/Readme.scons.txt
+++ b/Readme.scons.txt
@@ -199,7 +199,7 @@ Note:
at once. Following is the usage:
To build:
- $ auto_build.sh <path-to-android-ndk> <path-to-arduino-home>
+ $ auto_build.sh <path-to-android-ndk>
To clean:
$ auto_build.sh -c
diff --git a/arduino.scons b/arduino.scons
index 4ab2affff..fb9adfac1 100644
--- a/arduino.scons
+++ b/arduino.scons
@@ -3,9 +3,19 @@
##
Import('env')
-env.ImportLib('Time')
-if env.get('NET') == 'Ethernet':
+env.ImportLib('SPI')
+if 'ETHERNET' in env.get('TARGET_TRANSPORT'):
env.ImportLib('Ethernet')
-else:
+if 'WIFI' in env.get('TARGET_TRANSPORT'):
env.ImportLib('WiFi')
-env.ImportLib('SPI') \ No newline at end of file
+ env.AppendUnique(CPPDEFINES = ['ARDUINOWIFI'])
+if 'BLE' in env.get('TARGET_TRANSPORT'):
+ env.ImportLib('BLE')
+ env.ImportLib('RBL_nRF8001')
+
+env.ImportLib('Time/Time')
+# we have variety of macros for arduino!!
+if env.get('RELEASE'):
+ env.AppendUnique(CPPDEFINES = ['WITH_ARDUINO', '__ARDUINO__'])
+else:
+ env.AppendUnique(CPPDEFINES = ['WITH_ARDUINO', '__ARDUINO__', 'TB_LOG'])
diff --git a/auto_build.sh b/auto_build.sh
index c8f65da29..6eb7347e7 100755
--- a/auto_build.sh
+++ b/auto_build.sh
@@ -77,7 +77,7 @@ function help()
{
echo "Usage:"
echo " build:"
- echo " `basename $0` <path-to-android-ndk> <path-to-arduino-home>"
+ echo " `basename $0` <path-to-android-ndk>"
echo " clean:"
echo " `basename $0` -c"
}
diff --git a/build_common/arduino/SConscript b/build_common/arduino/SConscript
index 4c3a01f43..3455e265b 100644
--- a/build_common/arduino/SConscript
+++ b/build_common/arduino/SConscript
@@ -153,6 +153,19 @@ def __create_bin(env, source):
else:
hex = env.Command(name + '.hex', source, 'arm-none-eabi-objcopy -O binary $SOURCE $TARGET')
+#Currently supporting only megaADK build
+def __upload(env, binary):
+ if target_arch == 'avr':
+ protocol = __get_board_info(board, '.upload.protocol')
+ speed = __get_board_info(board, '.upload.speed')
+ port = '/dev/ttyACM0'
+ upload_cmd = arduino_home + '/hardware/tools/avr/bin/avrdude -C' + arduino_home +'/hardware/tools/avr/etc/avrdude.conf -p' \
+ + mcu + ' -c' + protocol + ' -P' + port + ' -b' + speed + ' -D -Uflash:w:' + binary + ':i'
+
+ print "Upload command: %s" %upload_cmd
+ install_cmd = env.Command('install_cmd', None, upload_cmd)
+ env.Default('install_cmd')
+
# Print the command line that to upload binary to the board
def __upload_help(env):
if target_arch == 'avr':
@@ -182,16 +195,12 @@ help_vars.Update(env)
Help(help_vars.GenerateHelpText(env))
target_arch = env.get('TARGET_ARCH')
+
+# Verify that the arduino, time, red bear, and nordic libraries are
+# installed. If not, get them and install them.
+SConscript(env.get('SRC_DIR') + '/extlibs/arduino/SConscript')
arduino_home = env.get('ARDUINO_HOME')
-if not arduino_home:
- print '''
-************************************* Error ***********************************
-* Arduino root directory isn't set, you can set enviornment variable *
-* ARDUINO_HOME or add it in command line as: *
-* # scons ARDUINO_HOME=<path to arduino root directory> ... *
-*******************************************************************************
-'''
- Exit(1)
+print 'ARDUINO_HOME = ' + env.get('ARDUINO_HOME')
# Overwrite suffixes and prefixes
if env['HOST_OS'] == 'win32':
@@ -397,4 +406,5 @@ __build_core(env)
env.AddMethod(__import_lib, "ImportLib") #import arduino library
#env.AddMethod(__build_core, "BuildCore") #build arduino core
env.AddMethod(__create_bin, "CreateBin") #create binary files(.eep and .hex)
+env.AddMethod(__upload, "Upload") #Upload binary to board
env.AddMethod(__upload_help, "UploadHelp") #print the command line that to upload binary to the boardf
diff --git a/extlibs/arduino/SConscript b/extlibs/arduino/SConscript
new file mode 100644
index 000000000..7028a414a
--- /dev/null
+++ b/extlibs/arduino/SConscript
@@ -0,0 +1,148 @@
+##
+# Script to install (if they do not exist) the Arduino library, Time library,
+# Red Bear Library, and Nordic library.
+##
+
+import os, subprocess, struct
+import urllib2, urlparse
+import SCons.Errors
+import shutil
+
+Import('env')
+
+target_os = env.get('TARGET_OS')
+src_dir = env.get('SRC_DIR')
+
+SConscript(src_dir + '/build_common/tools/UnpackAll.py')
+SConscript(src_dir + '/build_common/external_libs.scons')
+
+# Download
+if target_os == 'arduino':
+ arduino_home = env.get('ARDUINO_HOME')
+ if not arduino_home:
+ print 'Creating ARDUINO_HOME for Arduino lib'
+ print '''
+ *******************************************************************************
+ * Arduino root directory isn't set, you can set enviornment variable *
+ * ARDUINO_HOME or add it in command line as follows (Only set if your *
+ * version has fixes applied as depicted below. Press ctrl+c now if you *
+ * wish to manually set ARDUINO_HOME.): *
+ * # scons ARDUINO_HOME=<path to arduino root directory> ... *
+ *******************************************************************************
+ '''
+ arduinolib_dir = src_dir + '/extlibs/arduino/arduino-1.5.8'
+
+ if not os.path.exists(arduinolib_dir):
+ from sys import platform as _platform
+ if _platform == "linux" or _platform == "linux2":
+ archType = 8 * struct.calcsize("P")
+ print 'On %s-bit machine.' % (archType)
+ if archType == 32:
+ arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-linux32.tgz'
+ arduinolib_url = 'http://arduino.cc/download.php?f=/arduino-1.5.8-linux32.tgz'
+ else:
+ arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-linux64.tgz'
+ arduinolib_url = 'http://arduino.cc/download.php?f=/arduino-1.5.8-linux64.tgz'
+ elif _platform == "darwin":
+ arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-macosx.zip'
+ arduinolib_url = 'http://arduino.cc/download.php?f=/arduino-1.5.8-macosx.zip'
+ elif _platform == "win32":
+ arduinolib_zip_file = src_dir + '/extlibs/arduino/arduino-1.5.8-windows.zip'
+ arduinolib_url = src_dir + 'http://arduino.cc/download.php?f=/arduino-1.5.8-windows.zip'
+
+ # If the zip file is not already present, download it
+ if not os.path.exists(arduinolib_zip_file):
+ arduinolib_zip = env.Download(arduinolib_zip_file, arduinolib_url)
+ else:
+ arduinolib_zip = arduinolib_zip_file
+
+ # Unzip the lib
+ print 'Unzipping arduino lib...'
+ env.UnpackAll(arduinolib_dir, arduinolib_zip)
+ print 'Unzipping arduino lib complete'
+
+ # Remove downloaded file
+ os.remove(arduinolib_zip_file)
+ else:
+ arduinolib_dir = env.get('ARDUINO_HOME')
+
+ timelib_dir = arduinolib_dir + '/libraries/Time'
+
+ if not os.path.exists(timelib_dir):
+ timelib_zip_file = src_dir + '/extlibs/arduino/Time.zip'
+ timelib_url = 'http://playground.arduino.cc/uploads/Code/Time.zip'
+ # Install Arduino Time library
+ # If the zip file is not already present, download it
+ os.mkdir(timelib_dir)
+ os.chdir(timelib_dir)
+ if not os.path.exists(timelib_zip_file):
+ timelib_zip = env.Download(timelib_zip_file, timelib_url)
+ else:
+ timelib_zip = timelib_zip_file
+
+ # Unzip the lib
+ print 'Unzipping Arduino Time lib...'
+ env.UnpackAll(timelib_dir + '/Time', timelib_zip)
+
+ # Apply patches to ARDUINO_HOME directory.
+ os.chdir(arduinolib_dir)
+ print 'Patching Arduino libraries...'
+ os.system("find ./libraries/Time/Time/DateStrings.cpp -type f -exec dos2unix {} \;")
+ os.system("patch -p1 < " + src_dir + "/resource/csdk/connectivity/lib/arduino/arduino_libraries.patch --directory=" + arduinolib_dir)
+
+ # Remove downloaded file
+ os.remove(timelib_zip_file)
+
+ redbearlib_dir = arduinolib_dir + '/libraries/RBL_nRF8001'
+
+ if not os.path.exists(redbearlib_dir):
+ redbearlib_zip_file = src_dir + '/extlibs/arduino/25643e7b1b7da3740406325a471e3faa4b948747.zip'
+ redbearlib_url = 'https://github.com/RedBearLab/nRF8001/archive/25643e7b1b7da3740406325a471e3faa4b948747.zip'
+ if not os.path.exists(redbearlib_zip_file):
+ redbearlib_zip = env.Download(redbearlib_zip_file, redbearlib_url)
+ else:
+ redbearlib_zip = redbearlib_zip_file
+
+ # Unzip the lib
+ print 'Unzipping Red Bear lib...'
+ os.chdir(arduinolib_dir + '/libraries')
+ env.UnpackAll(redbearlib_dir, redbearlib_zip)
+
+ # Because the way Red Bear lib is distributed... All Red Bear source files must be moved up a few directories.
+ shutil.move('nRF8001-25643e7b1b7da3740406325a471e3faa4b948747/Arduino/libraries/RBL_nRF8001/', '.')
+ shutil.rmtree('nRF8001-25643e7b1b7da3740406325a471e3faa4b948747')
+
+ # Apply Red Bear patches
+ print 'Patching Red Bear library...'
+ os.chdir(arduinolib_dir + '/libraries/RBL_nRF8001/')
+ os.system("find . -type f -exec dos2unix {} \;")
+ os.system("patch -p1 < " + src_dir + "/resource/csdk/connectivity/lib/arduino/RBL_nRF8001.patch")
+
+ # Remove downloaded file
+ os.remove(redbearlib_zip_file)
+
+ nordiclib_dir = arduinolib_dir + '/libraries/BLE'
+
+ if not os.path.exists(nordiclib_dir):
+ nordiclib_zip_file = src_dir + '/extlibs/arduino/ble-sdk-arduino-0.9.5.beta.zip'
+ nordiclib_url = 'https://github.com/NordicSemiconductor/ble-sdk-arduino/archive/0.9.5.beta.zip'
+ if not os.path.exists(nordiclib_zip_file):
+ nordiclib_zip = env.Download(nordiclib_zip_file, nordiclib_url)
+ else:
+ nordiclib_zip = nordiclib_zip_file
+
+ # Unzip the lib
+ print 'Unzipping Nordic lib...'
+ os.chdir(arduinolib_dir + '/libraries')
+ env.UnpackAll(nordiclib_dir, nordiclib_zip)
+
+ # Because the way Nordic lib is distributed... All Nordic source files must be moved up a few directories.
+ shutil.move('ble-sdk-arduino-0.9.5.beta/libraries/BLE/', '.')
+ shutil.rmtree('ble-sdk-arduino-0.9.5.beta')
+
+ # Remove downloaded file
+ os.remove(nordiclib_zip_file)
+
+# Set the ARDUINO_HOME
+env.Replace(ARDUINO_HOME = arduinolib_dir)
+print 'ARDUINO_HOME = ' + env.get('ARDUINO_HOME')
diff --git a/resource/csdk/connectivity/common/SConscript b/resource/csdk/connectivity/common/SConscript
index 074742164..3ef0295f9 100644
--- a/resource/csdk/connectivity/common/SConscript
+++ b/resource/csdk/connectivity/common/SConscript
@@ -31,7 +31,7 @@ ca_common_src = [
]
if ca_os == 'arduino':
- env.Command(env.get('BUILD_DIR') + 'logger.c.o', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c.o' + ' $LINKFLAGS $CCFLAGS $CXXFLAGS ' + header + ' ' + 'common/src/logger.c')
+ env.Command(env.get('BUILD_DIR') + 'logger.c.o', None, '$CXX -o ' + env.get('BUILD_DIR') + 'logger.c.o' + ' $LINKFLAGS $CCFLAGS $CXXFLAGS ' + '-I' + Dir('.').srcnode().path + '/inc' + header + ' ' + Dir('.').srcnode().path + '/src/logger.c')
platform_src = [
env.get('BUILD_DIR') + 'logger.c.o',
]
@@ -46,3 +46,4 @@ else:
env.AppendUnique(CA_SRC = ca_common_src)
env.AppendUnique(CA_SRC = platform_src)
+
diff --git a/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript b/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
index a09112ed0..edf907680 100644
--- a/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
+++ b/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript
@@ -11,7 +11,14 @@ arduino_simplecs_env.PrependUnique(CPPPATH = [
])
arduino_simplecs_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
-arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'connectivity_abstraction','coap'])
+arduino_simplecs_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
+
+if 'Ethernet' == env.get('NET'):
+ transportLib = 'Ethernet'
+elif 'Wifi' == env.get('NET'):
+ transportLib = 'WiFi'
+
+arduino_simplecs_env.PrependUnique(LIBS = ['octbstack', 'connectivity_abstraction','coap',transportLib])
arduino_simplecs = arduino_simplecs_env.Program('SimpleClientServer', 'ocserver.cpp')
env.CreateBin('SimpleClientServer')
@@ -20,3 +27,10 @@ i_arduino_simplecs = arduino_simplecs_env.Install(env.get('BUILD_DIR'), arduino_
Alias('arduino_simplecs', i_arduino_simplecs)
env.AppendTarget('arduino_simplecs')
+
+if(arduino_simplecs_env['UPLOAD'] == True):
+ from sys import platform as _platform
+ if _platform == "linux" or _platform == "linux2":
+ arduino_simplecs_env.Upload(env.get('BUILD_DIR') + '/resource/csdk/stack/samples/arduino/SimpleClientServer/ocserver/SimpleClientServer.hex')
+ else:
+ print 'Please use appropriate install method for your developing machine. Linux is the only supported platform right now.'
diff --git a/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript b/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript
index edbc28bc0..f02c19f72 100644
--- a/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript
+++ b/resource/csdk/stack/samples/linux/SimpleClientServer/SConscript
@@ -15,6 +15,7 @@ samples_env.PrependUnique(CPPPATH = [
])
samples_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
+samples_env.AppendUnique(RPATH = [env.get('BUILD_DIR')])
samples_env.AppendUnique(LIBS = ['-lpthread'])
samples_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')])
samples_env.PrependUnique(LIBS = ['m', 'octbstack', 'oc_logger', 'connectivity_abstraction', 'coap'])