TinyOS-2.1.2在Ubuntu18.04上的安装(源码编译)

1.更换Ubuntu源

备份源:

 cp  /etc/apt/sources.list  /etc/apt/sources.list.bak  

更换源:

vim  /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main 
apt-get update

2.安装git

apt-get install  git

3.编译nesc

3.1 下载nesc源码

cd /opt  
git clone https://github.com/tinyos/nesc.git  

3.2 安装依赖包

apt-get install  make  autoconf  emacs  gperf  bison  flex 
apt-get install  openjdk-8-jdk  gcc  g++ 
apt-get install  gcc-multilib  g++-multilib 

3.3 编译nesc

cd nesc  
./Bootstrap  
./configure  
make  
make install  

3.4 查看版本

 nescc  --version 

在这里插入图片描述

4.编译tinyos-2.1.2

4.1下载tinyos-2.1.2源码

cd /opt  
git clone https://github.com/tinyos/tinyos-release.git  

4.2 安装依赖包

apt-get install  build-essential  graphviz  
apt-get install  gcc-msp430  

4.3 编译tinyos

mv  tinyos-release  tinyos-2.1.2  
cd  tinyos-2.1.2/tools  
./Bootstrap  
./configure  
make  
make install  

5.环境变量配置

5.1 配置tinyos.sh文件

新建tinyos.sh文件:

cd  tinyos-2.1.2  
touch  tinyos.sh 

输入以下内容:

#! /usr/bin/env bash
echo "Setting up for Tinyos-2.1.2"
export TOSROOT="/opt/tinyos-2.1.2" 
export TOSDIR="/opt/tinyos-2.1.2/tos" 
export CLASSPATH="$CLASSPATH:$TOSROOT/support/sdk/java:.:$TOSROOT/support/sdk/java/tinyos.jar" 
export MAKERULES="/opt/tinyos-2.1.2/support/make/Makerules" 

5.2 配置.bashrc文件

vim  /root/.bashrc  

在文件末尾输入以下内容:

#Setting for tinyos-2.1.2
source /opt/tinyos-2.1.2/tinyos.sh

执行命令

source  /root/.bashrc  

6.程序编译测试

cd  /opt/tinyos-2.1.2/apps/Blink  
make telosb  
make telosb install 

6.1 错误 no module named serial
在这里插入图片描述
执行以下命令:

apt-get  install  python-pip 
pip  install pyserial 

6.2 错误 no attribute setBaudrate
在这里插入图片描述

vim /usr/local/bin/tos-bsl 

self.serialport.setBaudrate(baudrate) 改为self.serialport.baudrate=baudrate
在这里插入图片描述

7.Listen Printf测试

7.1 运行 tos-install-jni

tos-install-jni  

7.2 测试 Listen

cd  /opt/tinyos-2.1.2/apps/tests/TestSerial  
make telosb install 
java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb 

如果报以下错误:
在这里插入图片描述

要么删除Makefile中java相关的编译语句
要么Makefile做如下修改:-target=null 改为 -target=$(PLATFORM)

7.3 测试 Printf

cd  /opt/tinyos-2.1.2/apps/tutorials/Printf  
make telosb install 
java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSB0:telosb 

8.优化

8.1 去掉Printf的新版提示

vim  /opt/tinyos-2.1.2/support/make/Makerules  

在20行左右加入:

CFLAGS += -I$(TOSDIR)/lib/printf
CFLAGS += -DNEW_PRINTF_SEMANTICS

8.2 去掉低功耗警告提示

vim  /opt/tinyos-2.1.2 /tos/chips/cc2420/lpl/DummyLplC.nc

删除第39行的warning语句

8.3 去掉-Wunused-but-set-variable提示

vim  /opt/tinyos-2.1.2/support/make/msp.rules 

删除51行 -Wall 参数

9.其他常见问题集锦

9.1. make telosb docs Python 脚本报编码错误
在这里插入图片描述
在/usr/lib/python2.7/xml/dom/minidom.py中加入

import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )

在这里插入图片描述

9.2 make micaz sim Python 脚本问题
在这里插入图片描述
将/opt/tinyos-2.1.2/support/make/sim.extra
第10行改为 PYTHON_VERSION=2.7
其正则表达式有问题

9.3 mathcalls-helper-functions.h 错误
在这里插入图片描述
找到math.h 位于:/usr/include/math.h
修改481行,将包含信息注释掉
在这里插入图片描述


版权声明:本文为a183635870原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。