2010년 11월 9일 화요일
Little endian format의 데이터 처리
12bit 이상의 AD를 사용하는 센서나 기타 하드웨어들은 2바이트 혹은 그 이상의 값을 뿌려준다. T1과 T2 버전은 방식이 달라 매번 헷갈린다.(참고로 T1은 리틀엔디안, T2는 빅엔디안)
간단하게 산술식을 통해 값을 변환한다든지 할 때 디버깅하기에는 안성맞춤인데, 어쩌다가 한번씩 만들려면 생각이 안 나서 기록을 해야겠다.
T1의 경우 예를 들어 packet의 10번째와 11번째의 값이 내가 원하는 값이라고 했을 때, packet[11] + packet[10] 이 되어야 하므로,
uint16_t value = ((0xFF00 & packet[11]) << 8) + (0x00FF & packet[10]);
요로케 처리하면 해당 값이 처리 된다.
T2에서는 uint16t value = packet[10] + packet[11]; 하시면 되겠다.
이제 value를 가지고 원하는대로 지지고 볶아서 요리하면 끝.
2010년 11월 3일 수요일
Active Message ID Allocation in TinyOS 2.1
The reserved pool is in the range 0-127 (0x00-0x7F). The AM IDs in this range are used by protocols distributed with TinyOS.
Here is a list of allocations for TinyOS 2.1:
* 0x70 - 0x7F are reserved for collection protocols maintained by
the Network Protocol Working Group.
0x70 - CTP routing beacon and LEEP (''tos/lib/net/ctp'', TEP 119, 123, and 124)
0x71 - CTP data packets (''tos/lib/net/ctp'', TEP 119, 123)
0x72 - CTP debug messages (''tos/lib/net/ctp'')
0x73 - MultiHopLQI routing beacon (''tos/lib/net/lqi'')
0x74 - MultiHopLQI data packets (''tos/lib/net/lqi'')
0x75 - MultiHopLQI debug messages (''tos/lib/net/lqi'')
* 0x60 - 0x6F are reserved for dissemination protocols maintained by
the Network Protocol Working Group.
0x60 - Drip (''tos/lib/net/drip'', TEP 118)
0x61 - DIP (''tos/lib/net/dip'', TEP 118)
* 0x50 - 0x5F are reserved for Deluge (''tos/lib/net/Deluge'')
maintained by the Network Protocol Working Group.
0x50 - AM_DELUGEADVMSG (advertisements)
0x51 - AM_DELUGEREQMSG (requests)
0x52 - AM_DELUGEDATAMSG (data)
0x53 - DELUGE_AM_FLASH_VOL_MANAGER (flash volume manager)
0x54 - DELUGE_AM_DELUGE_MANAGER (deluge manger)
* 0x3F - TinyOS NALP code (TEP 125) reserved by the Core Working
Group.
2010년 9월 20일 월요일
비트 연산자를 사용하는이유(비트 연산을 하는 이유)
비트 연산을 하는 가장 큰 이유는 연산속도다. bit는 최소정보단위로 다른 추상화된 정보들과 다르게 즉시 해석되어 전달되므로 연산 속도가 매우 빠르다는 장점이 있다.
다음으로 제어에 뛰어난 성능을 발휘한다. 레지스터의 직접 접근을 통해 bit 레벨 조작이 가능하다.
또한, 비트연산을 응용하면 복잡한 로직도 비교적 짧은 코드로 만들 수 있으며, 메모리의 최적화가 가능하다. 하지만 내공이 필요하다.
이제 비트연산자는 고급 언어의 등장과 컴퓨팅 파워의 향상으로 하위레벨의 펌웨어등에서나 찾아볼 수 있는 귀한 녀석이 되었다.
2010년 9월 13일 월요일
기술사에 도전하다.
항간에 “실력도 없고 경력도 없고 아는 건 쥐뿔도 없으면서 무슨 기술사” 라고 하지만 해 보고 이야기 하자. 아직 나는 시작도 겪어보지도 않았잖아.
그런 유쾌하지 않은 말들로 날 시험하지 마. 나에겐 한 번쯤 도전해 볼 만한 가치가 충분하니까…
더 큰 포부와 비전을 위해 화이팅!! (더도 말고 덜도 말고 항상 오늘만 같아라.)
2010년 9월 12일 일요일
What?, So What?, Now What?
생각의 프레임워크…
어떤 생각에 있어 그 틀을 잡기 위한 세 가지 질문에 대한 것으로 사고하는 능력을 업그레이드 할 수 있는 도구이다.
What?
관찰의 단계. 접한 새로운 정보를 받아들이는 단계로 그 대상을 파악하는 것으로 볼 수 있다.
So What?
받아들인 정보를 반영하는 단계. 그 정보가 나에게 어떤 영향을 주는지, 나와 무슨 상관이 있는지 생각해 볼 수 있다. 만약 아무 상관이 없다면 다음 단계로 진행할 필요가 없다.
Now What?
적용의 단계. 이제 내가 무엇을 해야 하는지를 생각해 본다. 구체적으로 어떻게 적용할 것인지, 어떻게 해결할 것인지를 생각해 볼 수 있다.
- futureshaper.tistory.com -
2010년 9월 7일 화요일
moodle LMS(Learning Management System)
reference site : http://www.moodle.org/
$> vim /etc/vsftdp.conf
------------------------------
…
anonymous_enable=NO
local_enable=YES
write_enable=YES
…
------------------------------
$> /etc/init.d/vsftpd restart
* LAPM 설치
게시물 참조.
* gd library 설치
$> apt-get install php5-gd
$> /etc/init.d/apache2 restart
* LAPM 설정
$> vim /etc/apache2/mods-available/php5.conf
------------------------------------------------------------------------
…
AddType application/x-httpd-php .php .phtml .php3 html
…
-------------------------------------------------------------------------
$> vim /etc/php5/apache2/php.ini
---------------------------------------
…
memory_limit=40M
session.bug_compat_warn=0
post_max_size=16M
upload_max_filesize=16M
…
---------------------------------------
$> /etc/init.d/apache2 restart
* phpMyAdmin 설치
$> cd /var/www
$> wget http://ftp.superuser.co.kr/pub/phpmyadmin/phpMyAdmin-2.5.4-php.tar.bz2
$> tar xvfz phpMyAdmin-2.5.4-php.tar.bz2
$> mv phpMyAdmin-2.5.4 phpMyAdmin
$> cd /phpMyAdmin
$> vim config.inc.php
--------------------------------------------------------------------------
…
$cfg[‘Servers’][$i][‘auth_type’]=’http’;
$cfg[‘Servers’]['$i'][‘password’]=’mysql root password 입력’;
--------------------------------------------------------------------------
* phpMyAdmin 설정
1. http://server/ ip address/phpMyAdmin 접속
2. 새 데이터베이스 만들기
‘moodle’ 로 DB 생성.
정상적으로 DB가 생성되면 시작페이지로 이동.
3. 사용권한 설정
페이지의 사용권한 탭 클릭.
새로운 사용자 추가를 위해 클릭.
위와 같이 로그인 정보를 입력 후 실행 버튼 클릭.
DB 권한 수정을 위해 ‘moodle’을 선택.
위와 같이 DB에 관련된 모든 권한에 체크.
* moodle 설치
http://download.moodle.org/ 에서 최신 릴리즈 버전을 다운로드 후 해당 파일을 /var/www 폴더로 이동
$> tar xvfz moodle-1.9.9.tgz
$> chmod –R 777 moodle
/var 폴더내에 moodledata 폴더 생성
$> mkdir moodledata
$> chmod 777 moodledata
$> chown –R nobody.nogroup moodledata
설치를 위해 웹브라우저를 이용한다.
http://192.168.1.31/moodle
Next 를 선택하고 설치 중간에 필요한 정보를 입력하고 계속 설치.
설치가 완료된 후 페이지 뷰를 위해 설정에 필요한 내용을 추가로 입력.
2010년 9월 5일 일요일
리눅스에서 특정 문자 및 문자열 찾기
리눅스에서 찾고자하는 문자를 포함하거나, 특정 문자열을 찾을 때 다음과 같은 방법을 이용하면 된다.
ex) opt/tinyos-1.x/tos/lib 폴더에서 MHOP_QUEUE_SIZE 를 찾고자 할 경우
$>find /opt/tinyos-2.x/tos/lib –type f –exec grep ‘MHOP_QUEUE_SIZE’ {} /dev/null \;
또 다른 방법으로는 해당 폴더의 위치로 이동하여
$>grep –rn MHOP_QUEUE_SIZE *
위와 같은 방법을 통해 어느 위치에 해당 내용이 있는지 쉽게 확인할 수 있다.
2010년 8월 30일 월요일
10대 유망 기술
전자부품연구원(KETI)에서 올 초 10대 유망 기술 분야를 발표했다. 2010년 이후 미래 산업을 전망한 유망 기술들로 8월 현재 진행되고 있는 사항들을 뉴스 등의 매스컴을 통해 쉽게 접할 수 있는 내용들이 다수 있다.
1. 스마트그리드
2. 3D TV
3. LED/OLED 조명
4. Interactive UI
5. Beyond 4G
6. 악성코드 분석 및 대응기술
7. 저전력 SoC
8. 차세대 음장기술
9. 고효율/고속충정 에너지 저장기술
10. 무선에너지 전송/충전
2010년 8월 29일 일요일
File Transfer (peer to peer)
: using two motes.
After receiving requests from so many people, I thought of writing this simple application which can transfer file between two computers
Assumptions:
- Environment used is: TinyOS 2.1.0 with Ubuntu
- Knowledge to compile "BaseStation" application (coming with TinyOS) with a modification in Makefile : CFLAGS += - TOSH_DATA_LENGTH
- Basic understanding of file operations in Java
- No other nodes are in the vicinity which are transmitting data at that time
- Run SerialForwarder with Java applications in TinyOS
- Transfer is only for "text files"
Steps:
General
- Download the code from here
- Install BaseStation in two motes
- Put one mote in computer 1 and other in computer 2.
- Run the SerialForwarder
Sender /Receiver
- ECopy the FileSender folder
- Open a shell, navigate to this above folder
- Type in CLASSPATH=/opt/tinyos-2.1.0/support/sdk/java/tinyos.jar:.
- Type in make
- Type in java FileSender
- Repeat the same with Receiver
- Enter the file name with absolute path and extension at sender side
- Wait for the message "File ended"
PS:
- Please come up with a reliable file transfer (like ftp)
- Please fix this code for any (byte) file instead of text files
- If you do any/both, please upload and post the link here
- by Gireesh -
2010년 8월 12일 목요일
2010년 7월 29일 목요일
Google Analytics
http://www.google.com/intl/ko_ALL/analytics/
로그 및 트래픽 분석, 최적화가 가능한 툴에 엑세스 하여 사이트 전략 및 마케팅, 운영등의 정책을 수립하고 강화하는데 도움이 되지 않을까?
2010년 7월 28일 수요일
Installation of Network Simulator NS2
NS2 Ver. : ns-allinone-2.34
xubuntu에 ns2 설치 전 꼭 필요한 필수 패키지들이 있다.
다음과 같이 설치한다.
$ apt-get install gcc, g++, libc6-dev, tcl8.5, tk8.5, tcl8.5-dev, tk8.5-dev, libxmu-dev
이미 xubuntu 배포판 설치 시 설치되어 있는 경우도 있으므로 패스~
패키지 설치가 끝나면 ns2 설치를 위해 다음 링크에서 2.34 버전을 다운로드 받는다.
http://sourceforge.net/projects/nsnam/files/allinone/ns-allinone-2.34/
다운로드 받은 ns-allinone-2.34를 /opt 에 위치시키고 압축해제 한 후 해당 폴더에서 ./install 명령을 통해 설치를 한다.
$ tar –xvf ns-allinone-2.34.tar.gz
$ ./install
설치가 정상적으로 완료되면 다음과 같은 내용을 볼 수 있다.
------------------------------------------------------------------------------
Please put /opt/ns-allinone-2.34/bin:/opt/ns-allinone-2.34/tcl8.4.18/unix:/opt/ns-allinone-2.34/tk8.4.18/unix
into your PATH environment; so that you'll be able to run itm/tclsh/wish/xgraph.
IMPORTANT NOTICES:
(1) You MUST put /opt/ns-allinone-2.34/otcl-1.13, /opt/ns-allinone-2.34/lib,
into your LD_LIBRARY_PATH environment variable.
If it complains about X libraries, add path to your X libraries
into LD_LIBRARY_PATH.
If you are using csh, you can set it like:
setenv LD_LIBRARY_PATH <paths>
If you are using sh, you can set it like:
export LD_LIBRARY_PATH=<paths>
(2) You MUST put /opt/ns-allinone-2.34/tcl8.4.18/library into your TCL_LIBRARY environmental
variable. Otherwise ns/nam will complain during startup.
After these steps, you can now run the ns validation suite with
cd ns-2.34; ./validate
For trouble shooting, please first read ns problems page
http://www.isi.edu/nsnam/ns/ns-problems.html . Also search the ns mailing list archive
for related posts.
-------------------------------------------------------------------------------
설치가 완료되면 path를 설정한다. ~/.bashrc 파일을 열고 다음의 내용을 추가한다.
# LD_LIBRARY_PATH
OTCL_LIB=/opt/ns-allinone-2.34/otcl-1.13
NS2_LIB=/opt/ns-allinone-2.34/lib
X11_LIB=/usr/X11R6/
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/opt/ns-allinone-2.34/tcl8.4.18/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/opt/ns-allinone-2.34/bin:/opt/ns-allinone-2.34/tcl8.4.18/unix:/opt/ns-allinone-2.34/tk8.4.18/unix
NS=/opt/ns-allinone-2.34/ns-2.34/
NAM=/opt/ns-allinone-2.34/nam-1.14/
PATH=$PATH:$XGRAPH:$NS:$NAM
저장한 후 설정된 내용을 적용시킨다.
$ source ~/.bashrc
마지막으로 실행은 다음과 같다.
$ ns
%
위와 같은 내용이 눈에 보인다면 성공이다... 종료는 exit 명령을 사용한다.
2010년 7월 21일 수요일
CC2420 in-line security option
The CC2420 radio chip supports three types of in-line security modes, leveraging the same underlying 128-bit AES encryption:
- Counter Mode Encryption (CTR)
- Cipher Block Chaining Message Authentication Code (CBC-MAC)
- Counter with CBC-MAC (CCM).
The CC2420 in-line security implementations add two new interfaces to the CC2420 radio stack in TinyOS 2.1: CC2420SecurityMode and CC2420Keys. The implementations are located in tos/chips/cc2420/security/ and the interfaces are located in tos/chips/cc2420/interfaces/. The design of the security implementation is based on the CC2420 specifications and the IEEE 802.15.4 2006 standards.
Transmitter Configuration
Makefile
Users intending to enable the security features MUST add the CC2420_HW_SECURITY flag in the Makefile.
CFLAGS+=-DCC2420_HW_SECURITY
Another point to note is the possible need for modifying the value of TOSH_DATA_LENGTH. Using different security options will add different amounts of additional overhead in the packet. For example, using the CBC-MAC authentication with a 16 byte MIC will require an additional 16 bytes in the payload portion of the message_t. While the security header is located in the cc2420_header_t, it takes up 6 additional bytes in the packet as well. The format of the security header can be found in tos/chips/cc2420/CC2420.h
Wiring (configuration file)
components new SecAMSenderC(AM_RADIO_COUNT_MSG) as AMSenderC;
components new AMReceiverC(AM_RADIO_COUNT_MSG);
components CC2420KeysC;
App.Receive -> AMReceiverC;
App.AMSend -> AMSenderC;
App.Packet -> AMSenderC;
App.CC2420SecurityMode -> AMSenderC;
App.CC2420Keys -> CC2420KeysC;
The AMSender interface MUST be wired to the SecAMSenderC component. The Packet interface is also provided by the SecAMSenderC and all packets that use the CC2420 in-line security features MUST be wired to this component. Note that the CC2420SecurityMode interface explained in the previous section is also provided by the SecAMSenderC component. The CC2420Key interface is provided by the CC2420KeyC component. The Receive interface can be wired as the case when no security is used because decryption happens transparently for the secured packets at the lower layers (below AM stack).
Implementation File
An array of 16 bytes SHOULD be set to store the desired key values. An example is shown below.
uint8_t key[16] = {0x98,0x67,0x7F,0xAF,0xD6,0xAD,0xB7,0x0C,0x59,0xE8,0xD9,0x47,0xC9,0x71,0x15,0x0F};
After the radio starts (SplitControl.startDone()), the following commands SHOULD be called to set the key values to a desired key register as explained above. The example below sets register 1 of the key registers (CC2420 offers registers 0 and 1) to a user specified key value shown above.
call CC2420Keys.setKey(1, key);
This call to the setKey command signals an event indicating the end of the key setting process.
event void CC2420Keys.setKeyDone(uint8_t keyNo, uint8_t* skey){}
This event is important for both the transmitting node. When this event is signaled, one of the following commands (provided by the CC2420SecurityMode interface) can be called for each packet transmission, with respect to the user-defined key values.
call CC2420SecurityMode.setCtr(msg, 1, 0);
call CC2420SecurityMode.setCbcMac(msg, 1, 0, 16);
call CC2420SecurityMode.setCcm(msg, 1, 0, 16);
For setCbcMac and setCcm, the last parameter is the size in bytes of the message authentication code. It can be 4, 8 or 16. Once the above steps are done,
call AMSend.send(msg, len);
can be called to send a packet just like any other packet transmissions.
Receiver Configuration
A receiver node that intends to enable the CC2420 Security features MUST add the CC2420_HW_SECURITY flag in the Makefile as well as the transmitter.
CFLAGS+=-DCC2420_HW_SECURITY
This enables all the decryption processes in the CC2420ReceiveP.nc file. Also, the receiver must have knowledge about the key values that a transmitter is using and SHOULD set the key registers with the user-desired keys before packets are exchanged. The example below sets register 1 of the key registers (CC2420 offers registers 0 and 1) to a user specified key value.
uint8_t key[16] = {0x98,0x67,0x7F,0xAF,0xD6,0xAD,0xB7,0x0C,0x59,0xE8,0xD9,0x47,0xC9,0x71,0x15,0x0F};
call CC2420Keys.setKey(1, key);
This call to the setKey command will signal an event indicating the end of the key setting process.
event void CC2420Keys.setKeyDone(uint8_t keyNo, uint8_t* skey){}
To use the CC2420Keys interface above, the following wiring MUST be done in the configuration file.
components CC2420KeysC;
App.CC2420Keys -> CC2420KeysC;
For the receiver, this event indicates that the radio is now ready to decrypt packets with the user-defined key values.
Examples
Sample implementations of applications that enable the CC2420 in-line security features (RadioCountToLeds and BaseStation) can be found in apps/tests/cc2420/TestSecurity/.
2010년 7월 5일 월요일
Contiki install and compile(for Linux)
1. install
cvs –d:pserver:anonymous@contiki.cvs.sourceforge.net:/cvsroot/contiki login
cvs –z3 –d:pserver:anonymous@contiki.cvs.sourceforge.net:/cvsroot/contiki co contiki-2.x
다운로드는 /opt에 위치.(/opt/contiki-2.x)
2. compile
$cd /opt/contiki-2.x/examples/sky로 이동
$make sky-motelist 명령으로 현재 연결된 mote 정보 출력.
$make blink.upload 명령으로 컴파일 및 업로드.
주의! 이미 컴파일 및 업로드를 위한 패키지가 설치되어 있으므로 이 부분은 생략.
2010년 6월 23일 수요일
contiki overview…
네트워크 스택으로는 uIP와 Rime를 지원하는데, uIP는 Contiki 개발자인 Adam Dunken이 제안한 8비트 MCU를 위한 TCP/IP 스택으로 임베디드 환경에서 인터넷을 통해 통신을 할 수 있도록 해준다. uIP는 현재 1.0버전까지 나와 있으며 IP,ICMP, UDP와 TCP 프로토콜을 지원한다. 일부 기능을 제거하고 느린 MCU 등을 고려하여 디자인되었기 때문에 delayed acknowledgment 기능을 제외하면 25,000kB/s 정도의 최대전송률을 가진다.
BSD socket 인터페이스와 유사한 protosocket 라이브러리를 제공하여 사용자가 쉽게 TCP 연결을사용할 수 있도록 하였으며, DNS resolver, SMTP e-mail sender, telnet server 등 다양한 애플리케이션을 함께 제공하고 있다. Rime은 저전력 통신을위해 구현된 멀티 홉 데이터 전송 프로토콜로 플러딩(flooding)을 통해 best-effort 브로드캐스팅을 지원하며, 컴파일 된 코드가 600byte 미만의 간단한 프로토콜이다.
Contiki 응용을 테스트해 볼 수 있는 Cooja라는 시뮬레이션 툴을 제공하며, 최근 릴리즈된 2.1버전에서는 노드의 에너지 상황을 실시간으로 모니터링 할 수 있는 기능을 지원한다.
현재 Contiki는 2010년 2월 16일 기준으로 2.4 ver. 이 릴리즈 되어 있으며 MAC, uIP/Rime, SensorAPI, COOJA/MSPSim, Micaz & Sensinode 8051/CC2430 등이 새롭게 지원되거나 확장되었다.
2010년 6월 14일 월요일
안드로이드 개발 환경 구축
우분투 10.04-alternate 에서 안드로이드 개발 환경 셋팅
이미 이클립스가 설치되어 있으므로 이 부분은 제외
1. http://developer.android.com/sdk/index.html 에서 리눅스 패키지를 다운로드 한 후 원하는 위치에 압축을 해제
2. bashrc 파일에 환경 변수 추가
$vim ~/.bashrc
export PATH=${PATH}:~/opt/android-sdk-linux_86/tools
3. 이클립스 플러그인 설치(Eclipse 3.5 galileo)
add site : http://dl-ssl.google.com/android/eclipse/
4. Android SDK 경로 설정
eclipse – window – preferences
SDK Location : /opt/android-sdk-linux_86
5. Emulator 등록
$/opt/android-sdk-linux_86/tools
$./android
Avaliable Packages에서 최신 버전 API, SDK 를 인스톨한다.
5. 테스트를 위한 가상 디바이스 생성
Virtual Devices 선택 후 New…
Create new AVD 창이 나타나면 Name, Target 등을 지정하고 Create 한다.
2010년 6월 10일 목요일
T2 TOSSIM
T2에서도 시뮬레이터 기능을 지원한다. 이는 센서 노드 어플리케이션이 올바르게 동작을 하는지 또는 오류가 발생할 여지가 없는지 등을 확인하기 위해 사용되지만 신뢰할 정도의 정확성이 요구되지는 않는다.
현재 T2에서는 micaz 플랫폼만을 지원하므로 telos 계열은 제외된다. 이 시뮬레이터를 이용하기 위해서는 avr toolchain이 필요하다. 하지만 TinyOS를 사용하는 사용자라면 이미 해당 환경이 갖추어져 있을 것이다. 또한, 시뮬레이션이 python을 이용하여 이루어지므로 python 관련 환경 설정도 갖추어져야 한다. 이 경우도 마찬가지로 TinyOS 를 사용하는 사용자의 경우라면 시뮬레이션을 위한 준비가 다 된 셈이다.
혹시라도 설정이 되어있지 않다면 대략 난감하므로 터미널을 이용하여 설정된 환경을 확인해 본다.
TinyOS env script file에 다음의 내용이 있는지 확인한다.
export PYTHONPATH=/opt/tinyos-2.x/support/sdk/python
없다면 추가한 후 환경 설정을 갱신한다.
다음으로 python –V 명령을 이용하여 python 버전을 확인해 본 후 sim.extra 파일에 명시된 버전과 일치하는지 확인한다.
$vim /opt/tinyos-2.x/support/make/sim.extra
만약 버전이 일치하지 않을 경우 현재 설치된 버전으로 수정한다.
또한, 옵션 추가를 위해 위와 같이 –shared 를 입력한 후 저장한다. 이제 시뮬레이션 실행을 위해 /opt/tinyos-2.x/apps/Blink로 이동한다.
$make micaz sim
위와 같이 컴파일하여 TOSSIM Library를 생성한다. BlinkC.nc 파일내에는 이미 디버그 메시지의 출력을 위한 dbg 함수가 작성되어 있다. 이 함수를 바탕으로 python을 실행하여 시뮬레이트 할 수 있다.
2010년 6월 9일 수요일
make pc error
어떤 이유에서인지 tinyos 시뮬레이션을 위한 어플리케이션 컴파일이 제대로 이루어지지 않는 문제가 발생함.
tinyos-help를 뒤져봐도 명확한 해결책이 나오지 않아 나름 정확하지는 않지만 gcc 문제(version)로 판단하여 현재 문제 해결 하였음.
2010년 6월 1일 화요일
TinyOS installation on xubuntu 10.04 alternate
$sudo apt-get update
* add packages
$sudo apt-get install vim cvs subversion autoconf automake1.9
$sudo apt-get install g++ gperf swig graphviz alien
* add tinyos repository
$vim /etc/apt/sources.list
deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main
$sudo apt-get update
$sudo apt-get install msp430-tinyos avr-tinyos
$sudo apt-get install tinyos-tools
* nesc compiler downgrade
nesc-1.2.8a-1.i386.rpm –> deb file converter
$sudo alien –c nesc-1.2.8a-1.i386.rmp
$sudo dpkg –i nesc-1.2.8a-1.i386.deb
* tinyos cvs download
$cvs -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos login
$cvs -z3 -d:pserver:anonymous@tinyos.cvs.sourceforge.net:/cvsroot/tinyos co tinyos-1.x tinyos-2.x tinyos-2.x-contrib
* tinyos env. script file(tinyos-1.x, tinyos-2.x)
TinyOS-1.x --------------------------------------------------------
unset CLASSPATH
export TOSROOT=/opt/tinyos-1.x
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$TOSROOT/tools/java
export MAKERULES=$TOSROOT/tools/make/Makerules
echo "--------------------------------"
echo "Currently, TinyOS-1.x env."
echo "--------------------------------"
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JDKROOT=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.
export MSPGCCROOT=/usr/msp430
export PATH=$MSPGCCROOT/bin:$PATH
---------------------------------------------------------------------
TinyOS-2.x --------------------------------------------------------
unset CLASSPATH
export TOSROOT=/opt/tinyos-2.x
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.
export MAKERULES=$TOSROOT/support/make/Makerules
echo "--------------------------------"
echo "Currently, TinyOS-2.x env."
echo "--------------------------------"
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JDKROOT=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.
export MSPGCCROOT=/usr/msp430
export PATH=$MSPGCCROOT/bin:$PATH
---------------------------------------------------------------------
* serial communication(RXTX)
download site http://www.rxtx.org/
$JAVA_HOME/jre/lib/i386
librxtxParallel.so / librxtxSerial.so
$JAVA_HOME/jre/lib/ext
RXTXComm.jar
tinyos java application source file modify
$cd /opt/tinyos-1.x/tools/java
$grep -rn javax.comm *
import javax.comm.*; –> import gnu.io.*;
$cd /opt/tinyos-1.x/tools/java
$./javapath
$tos-install-jni
$make
* Eclipse
$sudo apt-get install eclipse
/usr/lib/eclipse
excute eclipse - Help - Install New Software
add site http://download.eclipse.org/releases/galileo - Modeling download
nescdt plugin 및 yeti2 plugin 설치
tip : 이클립스에서 nescdt 플러그인을 설치하고 빌드하기 위해서는 tinyos 환경 설정이 우선 되어야 한다.
/etc/profile.d 에 tinyos.sh 파일 생성
$vim /etc/profile.d/tinyos.sh
----------------------------------------------------------------------
#Java
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JDKROOT=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=$CLASSPATH:.
#Java can find libtoscomm.so and libgetenv.so
export LD_LIBRARY_PATH=$JDKROOT/jre/lib/i386
#Conditional environmental setup for TinyOS-1.x
export TOSROOT=/opt/tinyos-1.x
export TOSDIR=$TOSROOT/tos
export MAKERULES=$TOSROOT/tools/make/Makerules
export CLASSPATH=$CLASSPATH:$TOSROOT/tools/java
# Finally set the path for the MSPGCCROOT
#export MSPGCCROOT=/usr/msp430
#export PATH="$MSPGCCROOT/bin:$PATH"
---------------------------------------------------------------------------
* LAPM, Samba, SSH
2010년 5월 13일 목요일
T2에서의 ADC Mapping
| * Configuration * generic configuration TestC() { provides interface DeviceMetadata; provides interface Read<uint16_t> as Test; provides interface ReadStream<uint16_t>; } implementation { components new AdcReadClientC(); Test = ADCReadClientC; components new AdcReadStreamClientC(); ReadStream = AdcReadStreamClientC; components TestP; DeviceMetadata = TestP; AdcReadClientC.AdcConfigure –> TestP; AdcReadStreamClientC.AdcConfigure –> TestP; } |
| * Module * #include “Msp430Adc12.h” module TestP { provides interface DeviceMetadata; provides interface AdcConfigure<const msp430adc12_channel_config_t *> } implementation { msp430adc12_channel_config_t config = { inch:INPUT_CHANNEL_A2, sref:REFERENCE_VREFplus_AVss, ref2_5v:REFVOLT_LEVEL_1_5, adc12ssel:SHT_SOURCE_ACLK, adc12div:SHT_CLOCK_DIV_1, sht:SAMPLE_HOLD_4_CYCLES, sampcon_ssel:SAMPCON_SOURCE_SMCLK, sampcon_id:SAMPCON_CLOCK_DIV_1 }; command uint8_t DeviceMetadata.getSignificantBits() { return 12; } async command const msp430adc12_channel_config_t * AdcConfigure.getConfiguration() { return &config; } } |
위와 같이 컴포넌트를 작성하여 최상위 어플리케이션에서 wiring을 통해 사용하면 된다.
TinyOS에서 CC2420 동작 원리
이 문서는 TinyOS에서 구현된 CC2420의 동작 원리를 분석하여, RF 메커니즘의 이해를 돕고자 하는데 그 의의가 있다.
1. IEEE 802.15.4 프로토콜
IEEE 802.15.4 의 standard feature는 다음과 같다.
The IEEE 802.15.4-2003 standard
• Data rates of 250 kbps, 40 kbps, and 20 kbps.
• Two addressing modes; 16-bit short and 64-bit IEEE addressing.
• Support for critical latency devices, such as joysticks.
• CSMA-CA channel access.
• Automatic network establishment by the coordinator.
• Fully handshaked protocol for transfer reliability.
• Power management to ensure low power consumption.
• 16 channels in the 2.4GHz ISM band, 10 channels in the 915MHz I and one
channel in the 868MHz band.
또한, CC2420의 간단한 specification을 보면 다음과 같다.
The IEEE 802.15.4-2003 standard
• true single-chip 2.4 GHz (16 channels in ISM band)
• Max data rate : 250Kbps
• Low current consumption (RX: 19.7 mA, TX: 17.4 mA)
위와 같이, CC2420은 IEEE 802.15.4 MAC hardware를 지원 가능하다. CSMA-CA에 대한 부분은 tinyos에서 B-MAC이란 MAC protocol을 사용해서 보완하고 있다.
2. CC2420 driver
CC2420은 MCU와 4-wire SPI-bus configuration interface (SI, SO, SCLK and CSn). 로 연결되어 SPI통신을 통한 동작을 기본으로 한다.
CSN은 SPI Chip select로, SPI 통신의 enable/disable을 담당한다. 일반적으로 low상태일 때, enable이 되고, High 일 때, disable이 된다. SI는 SPI Bus의 Input으로 사용되고, SO는 SPI Bus의 Output으로 사용된다. SCLK는 SPI Bus의 serial clock으로 사용된다.
atmega에서는 SPI를 컨트롤하는 레지스터를 갖고 있어서, 간단한 설정만으로도 SPI통신이 가능하다. 하지만 msp430 계열은 SPI를 컨트롤하는 레지스터가 없기 때문에, UART를 SPI mode로 변경하여 사용한다. TinyOS에서는 SPI mode의 초기화를 각 architectre별로 다음과 같이 구현하고 있다.
------------------------------------------------------------------------------
Atmega - 128
TOSH_MAKE_SPI_SCK_OUTPUT();
TOSH_MAKE_MISO_INPUT(); // miso
TOSH_MAKE_MOSI_OUTPUT(); // mosi
sbi (SPSR, SPI2X); // Double speed spi clock
sbi(SPCR, MSTR); // Set master mode
cbi(SPCR, CPOL); // Set proper polarity...
cbi(SPCR, CPHA); // ...and phase
cbi(SPCR, SPR1); // set clock, fosc/2 (~3.6 Mhz)
cbi(SPCR, SPR0);
// sbi(SPCR, SPIE); // enable spi port interrupt
sbi(SPCR, SPE); // enable spi port
------------------------------------------------------------------------------
------------------------------------------------------------------------------
MSP430
async command void USARTControl.setModeSPI() {
//check if we are already in SPI mode
if(call USARTControl.getMode() == USART_SPI)
return;
call USARTControl.disableUART();
call USARTControl.disableI2C();
atomic {
TOSH_SEL_SIMO1_MODFUNC();
TOSH_SEL_SOMI1_MODFUNC();
TOSH_SEL_UCLK1_MODFUNC();
IE2 &= ~(UTXIE1 | URXIE1); // interrupt disable
U1CTL |= SWRST;
U1CTL |= CHAR | SYNC | MM; // 8-bit char, spi-mode, USART as master
U1CTL &= ~(0x20); U1TCTL = STC ; // 3-pin
U1TCTL |= CKPH; // half-cycle delayed UCLK
if (l_ssel & 0x80) {
U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
U1TCTL |= (l_ssel & 0x7F);
}
else {
U1TCTL &= ~(SSEL_0 | SSEL_1 | SSEL_2 | SSEL_3);
U1TCTL |= SSEL_SMCLK; // use SMCLK, assuming 1MHz
}
if (l_br != 0) {
U1BR0 = l_br & 0x0FF;
U1BR1 = (l_br >> 8) & 0x0FF;
}
else {
U1BR0 = 0x02; // as fast as possible
U1BR1 = 0x00;
}
U1MCTL = 0;
ME2 &= ~(UTXE1 | URXE1); //USART UART module disable
ME2 |= USPIE1; // USART SPI module enable
U1CTL &= ~SWRST;
IFG2 &= ~(UTXIFG1 | URXIFG1);
IE2 &= ~(UTXIE1 | URXIE1); // interrupt disabled
}
return;
}
------------------------------------------------------------------------------
위에서 보듯이, atmega는 6~7번의 레지스터 세팅으로 SPI 통신을 초기화 할 수 있지만, msp430은 일반적인 UART 설정을 기본으로 초기화한다. 실제로, 일반 UART 초기화와의 차이점은 SPI module disable/enable을 제어하는 레지스터의 설정밖에 없다.(USPIEx) 초기화 후에, 간단한 SPI read/write function을 기본으로 작성된 여러가지 함수를 이용해서 CC2420을 제어하게 된다. 몇몇 중요 함수들의 예는 다음과 같다.
HPLCC2420.cmd(uint8_t addr) :
• CC2420으로 하나의 command를 보내고, 수신된 status 값을 리턴한다.
HPLCC2420.read(uint8_t addr) :
• CC2420으로부터 16-bit 레지스터 값을 받아온다.
HPLCC2420FIFO.readRXFIFO (uint8_t length, uint8_t *data) :
• RX FIFO 큐로부터 length만큼 값을 받아오고, data에 저장한다.
HPLCC2420FIFO.writeTXFIFO(uint8_t length, uint8_t *data) :
• data에 저장된 length만큼의 데이터를 TX FIFO에 write한다.
이제 이 함수들을 어떻게 사용하여 CC2420을 제어하는지 살펴보자.
CC2420의 드라이버 및 B-MAC이 구현된 부분은 /opt/tinyos-1.x/tos/lib/CC2420Radio 이다. 각 architecture별로 구현된 SPI/SPI응용 함수들을 이용하여 CC2420의 제어가 가능하다.
드라이버에서 가장 처음에 하는 일은 CC2420의 power on, reset toggle 을 하는 것이다.
------------------------------------------------------------------------------
//turn on power
call CC2420Control.VREFOn();
// toggle reset
TOSH_CLR_CC_RSTN_PIN();TOSH_wait();
TOSH_SET_CC_RSTN_PIN();TOSH_wait();
------------------------------------------------------------------------------
그 다음은 CC2420의 crystal을 enable시킴으로서, CC2420의 동작을 위한 최소한의 하드웨어 설정을 마친다. CC2420으로 CC2420_SXOSCON(0x01)이란 command를 보내면 crystal이 동작하게 된다.
------------------------------------------------------------------------------
async command result_t CC2420Control.OscillatorOn() {
......
status = call HPLChipcon.cmd(CC2420_SXOSCON); //turn-on crystal
......
------------------------------------------------------------------------------
CC2420의 send 모드는 크게 두가지로 나눌 수 있다. 채널이 clear될 때까지 기다리다가 clear되는 순간 전송을 하는 방식과, 채널의 상태에 관계없이 전송을 하는 방식이다.
------------------------------------------------------------------------------
async command result_t CC2420Control.TxMode() {
call HPLChipcon.cmd(CC2420_STXON);
return SUCCESS;
}
//Shift the CC2420 Radio into transmit mode when the next clear channel
is detected.
async command result_t CC2420Control.TxModeOnCCA() {
call HPLChipcon.cmd(CC2420_STXONCCA);
return SUCCESS;
}
------------------------------------------------------------------------------
CC2420의 receive모드는 다음과 같다
------------------------------------------------------------------------------
async command result_t CC2420Control.RxMode() {
call HPLChipcon.cmd(CC2420_SRXON);
return SUCCESS;
}
------------------------------------------------------------------------------
CC2420Control 에 모듈의 초기화, TX/RX 모드 함수, RF power및 frequency 설정을 하는 기본 함수들이 포함되어 있다면, CC2420Radio는 송/수신에 직접적이면서 복잡한 함수들이 포함되어 있다. 송신 함수는 sendPacket(), startSend(), tryToSend()함수로 구현되어 있다. startSend는 말그대로 송신을 시작하는 함수로, TXFIFO에 송신할 패킷을 length만큼 write하게 된다. 이 함수가 종료되면 패킷들이 FIFO에서 송출되기를 기다린다.
------------------------------------------------------------------------------
task void startSend() {
// flush the tx fifo of stale data
if (!(call HPLChipcon.cmd(CC2420_SFLUSHTX))) {
sendFailed();
return;
}
// write the txbuf data to the TXFIFO
if (!(call HPLChipconFIFO.writeTXFIFO(txlength+1,(uint8_t*)txbufptr))) {
sendFailed();
return;
}
}
------------------------------------------------------------------------------
sendPacket은 RF로 패킷을 보내는 함수이다. tryToSend에서 call되어 사용되어 지며, 채널이 clear되면 전송되는 방식을 사용한다.
------------------------------------------------------------------------------
void sendPacket() {
uint8_t status;
call HPLChipcon.cmd(CC2420_STXONCCA);
status = call HPLChipcon.cmd(CC2420_SNOP);
……..
}
------------------------------------------------------------------------------
tryToSend는 CCA핀을 read했을 때, High상태라면, 즉 채널이 clear하다면 sendPacket을 call하여 패킷을 전송하고, 채널이 사용중이라면 normal operation을 계속해서 수행한다.
------------------------------------------------------------------------------
void tryToSend() {
…………..
// if a FIFO overflow occurs or if the data length is invalid, flush
// the RXFIFO to get back to a normal state.
if ((!TOSH_READ_CC_FIFO_PIN() && !TOSH_READ_CC_FIFOP_PIN())) {
flushRXFIFO();
}
if (TOSH_READ_RADIO_CCA_PIN()) {
atomic stateRadio = TX_STATE;
sendPacket();
}
else {
// if we tried a bunch of times, the radio may be in a bad state
// flushing the RXFIFO returns the radio to a non-overflow state
// and it continue normal operation (and thus send our packet)
if (countRetry-- <= 0) {
flushRXFIFO();
countRetry = MAX_SEND_TRIES;
if (!post startSend())
sendFailed();
return;
}
……………
}
------------------------------------------------------------------------------
tryToSend는 startSend가 종료되는 시점에 실행이 된다. 즉 startSend에서 TXFIFO를 채우면 HPLChipconFIFO.TXFIFODone()이 실행되고, 이 함수안에서 tryToSend를 실행하게 되어, FIFO에 write된 패킷이 무선으로 전송된다.
rxMode로 설정되어 있을 때, 같은 주파수대의 패킷이 들어오면, FIFOP에 interrupt가 발생한다. Interrupt가 발생했을 때, FIFOP.fired 라는 인터럽트 함수가 실행하게 되고, 이는 수신된 패킷을 RXFIFO로 write한다. RXFIFO로 값이 모두 들어오면, HPLChipconFIFO.RXFIFODone()라는 함수가 실행된다.
------------------------------------------------------------------------------
async event result_t FIFOP.fired() {
…………..
/** Check for RXFIFO overflow **/
if (!TOSH_READ_CC_FIFO_PIN()){
flushRXFIFO();
return SUCCESS;
}
atomic {
if (post delayedRXFIFOtask()) {
call FIFOP.disable();
}
else {
flushRXFIFO();
}
}
// return SUCCESS to keep FIFOP events occurring
return SUCCESS;
}
------------------------------------------------------------------------------
HPLChipconFIFO.RXFIFODone()이 실행되면 데이터 예외처리를 거쳐서 정상적인 length의 패킷을 rxbufptr 버퍼에 저장한다. rxbufptr에 할당이 되는 *data는 TOS_MsgPtr 의 구조체 변수 크기에 맞게 바이트 단위로 parsing되서 저장된다. length가 길면 패킷은 버려지고, 짧으면 crc, RSSI, LQI값을 맟춰서 할당한다.
------------------------------------------------------------------------------
async event result_t HPLChipconFIFO.RXFIFODone(uint8_t length, uint8_t *data){
…………….
rxbufptr = (TOS_MsgPtr)data;
……………
if (rxbufptr->length > TOSH_DATA_LENGTH) {
flushRXFIFO();
atomic bPacketReceiving = FALSE;
return SUCCESS;
}
// adjust destination to the right byte order
rxbufptr->addr = fromLSB16(rxbufptr->addr);
// if the length is shorter, we have to move the CRC bytes
rxbufptr->crc = data[length-1] >> 7;
// put in RSSI
rxbufptr->strength = data[length-2];
// put in LQI
rxbufptr->lqi = data[length-1] & 0x7F;
……………
}
------------------------------------------------------------------------------
지금까지 TinyOS에서의 CC2420이 마이크로 컨트롤러와 어떻게 통신을 하고 동작을 하는지를 알아보았다. 물론 위의 설명은 CC2420의 동작원리를 충분히 이해하기엔 너무 개략적이고 의미 중심적이다. 따라서 윗글은 CC2420소스를 처음 접하여 분석하고자 하는 분에게 소스의 전반적인 구성을 이해하는데 참조할 수 있는 자료라 할 수 있겠다.
2010년 5월 11일 화요일
Dissemination
이 기법은 패킷 손실이나, 일시적인 통신 단절등에 상당히 잘 견디며, 단순히 패킷을 노드 간에 반복 전달하는데 그치는 플러딩(flooding) 방식과는 달리 Dissemination 기법은 네트워크에 연결되어 있는 모든 노드들이 궁극적으로는 일관된 값을 갖도록 보장한다. 전송할 데이터의 크기에 따라 이 프로토콜의 성능은 크게 다르며, 수십 KB의 데이터를 dissemination하는 것은 몇 Bytes를 전송하는 경우와는 약간 다른 프로토콜을 요구하는데, 자세히 살펴보면 근본적으로는 매우 유사하다. Dissemination 프로토콜을 제어와 데이터 트래픽으로 나눠보면, 데이터 트래픽 프로토콜은 데이터의 크기에 밀접한 관련이 있지만, 제어 트래픽 프로토콜은 동일하거나 비슷한 경향을 보인다. 예를 들어, UC Berkely에서 개발한 Deluge 바이너리 프로그래밍 서비스는 바이너리(실행 프로그램)에 대한 메타 정보를 전파한다. 이 과정에서 노드들이 자신들이 갖고 있는 바이너리의 정보가 전달받은 정보와 다르면, 그들은 자신의 노드에 있는 바이너리가 잘못되었거나 새로운 바이너리가 필요하다는 것을 알 수 있다.
이 기법에서는 어떤 노드라도 네트워크에게 자신이 새로운 값을 생성했다고 알림으로 네트워크 전체가 일관된 상태로 수렴하도록 요구할 수 있다. 그리고, 모든 노드들이 이 값에 동의하면 네트워크 전체에 걸쳐 동일한 값으로 수렴한다. 이와 같은 방법으로 작은 데이터들을 Dissemination 할 수 있다면 센서 네트워크의 중요한 기능을 담당할 수 있다. 예를 들면, 작은 프로그램을 네트워크에 전달하거나 네트워크의 재구성, 질의 또는 명령, 재프로그램등을 지원할 수 있다.
Collection
TinyOS에서는 트리를 구성하기 위해 CTP(Collection Tree Protocol)을 사용한다. 네트워크에서 임의의 노드가 자신이 루트라고 알리면 네트워크의 노드들은 루트 노드를 중심으로 라우팅 트리들을 구성한다. 이 때 각 노드들은 루트 노드로 향하는 경로를 설정하기 위해 라우팅 기울기(routing gradient)를 계산한다. 즉, 각 노드는 싱크 노드와의 근접성을 측정하고, 이를 바탕으로 싱크 노드에 최대한 근접하는 링크를 선택하며 점진적으로 경로를 설정해 간다.
CTP는 라우팅 기울기로 ETX(Expected transmissions) 값을 사용한다. 루트 노드의 ETX 값은 0으로 정의하며, 어떤 노드의 ETX 값은 자신의 부모 노드가 갖는 ETX 값과 해당 노드에서 부모 노드로의 링크가 갖는 ETX 값을 더한 값을 갖는다. 이와 같은 상황에서 임의의 노드는 루트 노드로의 경로 설정 시에 가장 낮은 ETX 값을 갖는 링크를 선택하고, 이 링크에 연결된 노드를 부모 노드로 기록하며, 이 과정이 루트 노드를 시작으로 전체 네트워크에 이르기까지 반복된다.
위 그림은 CTP를 구성하는 컴포넌트들을 나타내고 있으며, 이 가운데 CtpP 컴포넌트가 핵심 기능을 제공한다. 특히 CtpP는 한 홉(Hop) 간 ETX 값을 측정하기 위해 LinkEstimatorP 컴포넌트를 포함하며, 이 값을 이용해 다음 라우팅 링크를 결정하기 위해 CtpRoutingEngineP 컴포넌트를 사용한다. 마지막으로 라우팅 링크로의 패킷 전송을 위해 CtpForwardingEngineP 컴포넌트가 사용된다. 보다 상세한 수준의 컴포넌트는 TinyOS에서 제공하는 docs 유틸리티를 활용하여 컴포넌트들의 연결 구조를 파악할 수 있다.
이와 같은 구성으로 CTP가 구현되어 있으며 위에서 설명한 동작방식을 통해 센서 네트워크 내의 임의의 노드가 데이터를 생성하면, 자신의 부모 노드를 향해 데이터를 전달(forwarding)한다. 이를 통해 루트는 자신의 하위에 있는 모든 노드로부터 발생한 데이터를 수집하는 역할을 담당한다.
네트워크가 여러 루트를 가졌을 때, Tree 형태의 forest를 구성하게 된다.
하지만 단순한 Colletcion 프로토콜은 여러 문제에 직면한다. 가령 전달 경로에 루프(loop)가 생기거나, 데이터의 중복 전송 문제 등이 발생할 수 있다. 이 때문에 일반적으로 분산된 트리를 구성하는 알고리즘에 제한을 둔다. 다음은 이와 같은 알고리즘이 해결해야 할 과제들이다.
▪Loop detection
자손 중 하나를 부모 노드로 선택하는 상황 검출
▪Duplicate suppression
네트워크에서 패킷의 중복 전송 원인이 되는 ACK의 손실을 탐지
▪Link estimation
한 홉간의 이웃과의 Link quality를 측정
▪Self-interference
다음 패킷의 경로를 이전 패킷들과 간섭이 생기는 경로로 라우팅하는 것을 방지
2010년 5월 10일 월요일
리눅스 권한 설정
리눅스에서 권한 설정은 chmod(change mode) 명령을 이용한다.
리눅스는 사용자 번호(UID)와 그룹번호(GID)를 가지고 모든 사용자를 구분하는데, 파일은 그것을 생성한 소유자에게 속해 있으며 이 명령을 통해 폴더 및 파일에 대한 접근 권한을 줄 수 있다.
- chmod [option] octal-mode file(s)
- chmod [option] symbolic-mode file(s)
option
| -R 서브 디렉토리의 파일까지 재귀적으로 실행 -f 자기 소유가 아닌 파일에 변경 시도 -v 변경되는 모드에 대해 출력 |
octal-mode
symbolic-mode
참고로 chmod –R 777 /share * 명령을 이용하면 share 폴더에 있는 하위 폴더의 파일내용까지도 파일소유자, 그룹, 기타 사용자까지 모두 읽기, 쓰기, 실행을 허용한다는 것이다.
2010년 5월 2일 일요일
TOSH_uwait();
참고로 TOSH_uwait(10000); == 10ms == 0.01sec 가 된다.
이 함수는 /opt/tinyos-1.x/tos/platform/msp430/msp430hardware.h 에 정의 되어 있다.
2010년 4월 29일 목요일
Install TinyOS and the 8051wg platforms
- A TinyOS 2 installation, in Windows using Cygwin or natively in Linux or similar. Inline is only supported for x86 platforms.
- A 8051 compiler
- Keil PK51 (any version)
- IAR Workbench version 7 or later
- SDCC version 2.9.0 or later
- A copy of the port from TinyOS-contrib
- Hardware programming tools for you particular chip (eg. cc2430)
1. TinyOS 2 install
TinyOS 2 must be installed separate from this port, either in Windows through Cygwin or natively in Linux (or similar). TinyOS version 2.1. and NescC version 1.3.0 are supported presently.1.1 Windows trough Cygwin
For Cygwin or Linux users follow the instructions from docs.tinyos.net. For Cygwin users remember to install the packages rpm and gcc-mingw. As a bare minimum you need to install the nescc, tinyos-tools, tinyos-deputy and tinyos packages.
$ rpm -i nesc-1.3.0-1.cygwin.i386.rmp
$ rpm -i tinyos-tools-1.3.0-1.cygwin.i386.rpm
$ rpm -i tinyos-deputy-1.1-1.cygwin.i386.rpm
$ rpm -i tinyos-2.1.0-1.cygwin.noarch.rpm1.2 Windows trough virtual machine
Alternatively Windows users may want to run the Linux through a virtual machine such as Virtual PC or VMWare Server. XubunTOS provides an install image with TinyOS pre-installed. XubunTOS can also be downloaded ad a ready-to-run virtual machine here.1.3 Linux native install
Linux (and similar) are supported natively, follow the appropriate instructions on docs.tinyos.net your distribution. For example, the installation of TinyOS 2.1 on Ubuntu, is described here.2. 8051 compiler
To compile programs using this port an 8051 C-compiler is required. We recommend Keil PK51 - this port is written and tested using the Keil compiler. In addition IAR or SDCC may be used, but these are not tested. There are numerous other companies providing compilers that might or might not work, but additional compilers are not supported through the tool chain. Which compiler to used is selected using the environment variable MCS51_COMPILER (see Section 3).Keil and IAR are Windows only compilers, to use them in Linux they are run through Wine. Each compiler is installed in a separate Wine directory (eg. .wine.keil for Keil) to avoid interference. First install wine and create the appropriate wine directory (using Ubunto or Xubuntos):
apt-get install wine
env WINEPREFIX=~/.wine.keil wineprefixcreate2.1 Installing Keil PK51
Keil PK51 is a commercial 8051 compiler that can be purchased from http://www.keil.com/. A trial version is available with a 2 KiB code size limit on the compiled binaries. For either Cygwin or Wine install Keil in the default location (C:Keil).2.1.1 Linux
The tool chain assumes Keil is install using the Wine environment in the directory named ~/.wine.keil. Run the Keil installer using Wine (either from the provided CD-rom or downloaded binary):
WINEPREFIX=$(HOME)/.wine.keil wine C51V809A.EXETo enter your license code start the uVision development environment and enter it the same way you would in Linux:
WINEPREFIX=~/.wine.keil wine "C:\Keil\UV3\Uv3.exe"2.1.2 Windows
Simply install the compiler using the appropriate installer.2.2 Installing SDCC
SDCC is a free, open souce C compiler with native Linux and Windows support. SDCC versions 2.6 and greater provide native inline support. We have not been able to successfully compile a TinyOS application using this inliner. We recommend using the stand alone inline tool provided with this TinyOS port.2.2.1 Linux
To install sdcc using Debian, Ubuntu or XUbunTOS run the following command:
apt-get install sdcc sdcc-libraries2.2.2 Windows
Download and install the compiler from http://sdcc.sourceforge.net/. Answer yes to the question "Add to path".2.3 Installing IAR
Iar is a commercial compiler for Windows. It has a 30 day evaluation is available here. In either Windows or Linux set the path of the compiler in the environment variable MCS51_IAR_PATH, for example the default is:
export MCS51_IAR_PATH=Program\ Files/IAR\ Systems/Embedded\ Workbench\ 4.0\ Evaluation\ version/common/bin/2.3.1 Linux
Install the compiler using Wine:
env WINEPREFIX=~/.wine.iar wine EW8051-EV-730B.exe2.3.1 Windows
Simply install the compiler using the native installer.3. 8051 port from TinyOS-contrib
The code is located in the TinyOS-2.x-contrib section and is downloaded separately from TinyOS. See download for more.3.1 8051 port directory
The the archive above contains the code in a directoryh namednamed tinyos-2.x-contrib/diku. This directory must be places in par particular location (or speficfied in the variable below).By placing the directory in the following locations the build system will automatically be able to locate the port
- For cygwin c:\cygwin\opt
- Linux /opt
3.2 Environment variables
The ports need a few environment variables in addition to the default TinyOS variables. These variables enable the TinyOS make system to locate the Make rules and the source files.- TOSDIR (location of T2 tree)
- MAKERULES (location of T2 Makerules)
- TOSMAKE_PATH list of directories to search for .target files (separated by spac"
- CONTRIBROOT (root of the contrib directory)
- MCS51_COMPILER select compiler one of (keil, sdcc or iar)
- MCS51_WINE_IAR_PATH wine directory for Keil (default ~/.wine.keil)
- MCS51_WINE_KEIL_PATH wine directory for IAR (default ~/.wine.iar)
- MCS51_IAR_PATH Path to IAR compiler
cd tinyos-2.x-contrib
source diku/env4. Hardware programming tools.
In order to transfer the compiled binary to the chip you need the chip or platform maintainer's tool for this purpose.- Texas Instrumenst (ChipCon) Development Kit
- ChipCon Flash Programmer. The programmer is only available for Windows. Other users will have to dual boot or run in an emulator. http://focus.ti.com/docs/toolsw/folders/print/cc2430dk.html#supportsoftware
- SiLabs 8051
- SiLabs provides a Windows GUI programmer. For Linux (and similar) the ec2drv project provides a command line programmer
- nRF24e1
- Nordic VSLI provides a programmer for Windows
- Sensinode Nano
- http://www.sensinode.com/top/information.php?info_id=10
5. Test the setup
With the above prerequisites your setup should be ready to go. To test the setup compile one of the example applications:
cd mcs51/apps/BlinkNoTimer
make cc2430emIf all goes well you should see the following message:
...
GENERATING INTEL HEX FILE: app.hex
compiled BlinkNoTimerTaskAppC to a cc2430em binary
Code size of app.o
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 635 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 4 9
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
Total sizes
Program Size: data=9.0 xdata=10 const=0 code=6946. Trouble shooting
In case of problems start your setup using the mcs51_env_check.sh script
./diku/mcs51/support/make/mcs51/mcs51_env_check.sh -v
2010년 4월 21일 수요일
MSP430Fxx series SPI Communication.
먼저 하드웨어를 살펴보자.
MSP430은 USART0과 USART1 이 존재한다.
USART0은 uart, i2c, spi 가 가능하며, USART1은 uart, spi가 가능하다.
여기서 USART0은 CC2420과 연결되어 무선 통신에 쓰이므로 무선 통신을 사용하기 위해서 패스하고, USART1을 이용하여 spi를 사용하도록 한다.
여기서 MSP430의 결점(?)이 드러나기 시작한다. MSP430 family는 SPI를 직접 컨트롤 할 수 있는 레지스터가 없다.
앞서 언급한 듯이 USART1은 uart와 spi 통신이 가능한데, 두 가지 통신을 한꺼번에 하지 못한다.
즉, 공유자원으로 사용한다는 것이다. uart 통신을 하고자 한다면 uart 모드로 변경해야 하고, spi 통신을 하고자 한다면 spi 모드로 변경해서 사용해야한다.
둘 다 사용하고자 한다면 소프트웨어적으로 스케줄링해서 사용할 수 있다.
tinyos에서는 이를 어떻게 해야 하는지는 뒤에서 언급하도록 한다.
USART1을 SPI 모드로 사용할 경우 p.5.1 ~ p5.3이 쓰인다.
p.5.1은 마스터 모드인 경우 데이터 출력, 슬레이브인 경우 데이터 입력이 가능하다. (SIMO1)
p.5.2는 반대로 마스터 모드인 경우 데이터 입력, 슬레이브인 경우 데이터 출력이 가능하다. (SOMI1)
p.5.3의 경우 마스터인 경우 시리얼 클럭의 출력, 슬레이브인 경우 시리얼 클럭의 입력이 가능하다.
만약 MSP430을 마스터로 사용한다면 어떤 핀을 제어해야 하는지 감이 올 것이다.
다시 돌아와서 tinyos의 경우 USART1의 uart와 spi를 위해 HPL단의 컴포넌트에 레지스터 셋팅이 되어 있다.
(/opt/tinyos-1.x/tos/platform/msp430/HPLUSART1M.nc)
이를 사용하기 위해서는 top-level app단에서 인터페이스를 연결하여 call 하면 된다.
(/opt/tinyos-1.x/tos/platform/msp430/HPLUSARTControl.nc)
참고로 슬레이브 모듈에 따라 레지스터를 변경 적용해야 하는 경우도 있으니 MSP430Fx의 데이터시트를 꼭 참고해야 한다.
TIP.
TinyOS에서 StdControl interface를 이용하여 초기화할 때, SPI 모드도 초기화 하게 되면 동작이 되지 않는다. 그러므로 스케줄러에 의해 모트의 동작이 시작할 때 초기화하고 SPI로 동작하도록 해야 한다.
2010년 3월 24일 수요일
Sensor Node Reboot !!
* MSP430
void reboot() {
WDTCTL = 0; //watchdog timer control
while(1);
}
* Atmega128
void reboot() {
wdt_enable(1); //watchdog timer
while(1);
}
2010년 3월 23일 화요일
What's TOSH?
/opt/tinyos-1.x/tos/platform/msp430/msp430hardware.h 파일의 내용을 보면 아래와 같은 매크로가 정의되어 있다.
2010년 3월 9일 화요일
vmware image 하드 공간 확장
vmware-vdiskmanager.exe -x 10Gb "E:\Virtual image\Ubuntu\Ubuntu.vmdk"
2010년 2월 16일 화요일
여러 개의 센서를 이용한 패킷 전송 방법
1. 센서의 갯수 만큼 타이머를 할당하여 타이머 이벤트에 따라 제어 및 전송하는 방식
- 센서로부터 센싱하는 시간이 대체적으로 길거나 신뢰성 있는 패킷 전송을 필요로 할 때 사용
- 전송시간이 길며 배터리 소모면에서 불리하다.
- 예시
event void Temperature.readDone(error_t result, uint16_t data){
//inject data to payload//
}
event void Humidity.readDone(error_t result, uint16_t data){
//inject data to payload//
}
event error_t AnalTemperature.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
}
event error_t Light.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
}
event error_t Microphone.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
}
event error_t Gyro.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
call Send.sendPacket(transmitPacketPtr);
}
event void Timer.fired(){
if(count % 6 == 1) call Temperature.read();
else if(count % 6 == 2) call Humidity.read();
else if(count % 6 == 3) call AnalTemperature.getData();
else if(count % 6 == 4) call Light.getData();
else if(count % 6 == 5) call Microphone.getData();
else call Gyro.getData();
count++;
}
2. 순차적으로 센서를 제어하는 방식으로 마지막으로 센싱된 후 패킷을 전송하는 방식
- 센싱이 빠르며 패킷 전송 또한 빠르다.
- 적절한 타이머를 사용하지 않으며 패킷 손실 및 전송 실패가 발생할 수도 있다.
- 예시
event void Temperature.readDone(error_t result, uint16_t data){
//inject data to payload//
call Humidity.getData();
}
event void Humidity.readDone(error_t result, uint16_t data){
//inject data to payload//
call AnalTemperature.getData();
}
event error_t AnalTemperature.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
call Light.getData();
}
event error_t Light.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
call Microphone.getData();
}
event error_t Microphone.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
call Gyro.getData();
}
event error_t Gyro.dataReady(uint16_t data, uint8_t status){
//inject data to payload//
call Send.sendPacket(transmitPacketPtr);
}
2010년 1월 18일 월요일
네트워크에서의 지연과 손실
processing delay
transmission delay
propagation delay
end-to-end delay
packet loss
Nodes do not appear when using "lowpower"
make tmote lowpower
2. Then there is a known bug that causes synchronization to fail.
3. To prevent this bug, download this new version of NetSyncM.nc and copy it to the /tos/lib/netsync directory, replacing the existing file.
----------------------------------------------------------------------------------
void setSyncMaster() {
uint32_t now;
// if a find is in progress, disable the find
call SPNeighbor.findDone();
atomic {
m_smsg->hopcount = 0;
m_nexton = m_nextoff = 0;
broadcast.addr = TOS_BCAST_ADDR;
m_smsg->global_time = m_smsg->local_time = call LocalTime.get();
now = m_smsg->global_time & 0xFFFF0000;
broadcast.timeon = now + (TIME_ON 1 PERIOD);
broadcast.timeoff = now + (TIME_OFF 1 PERIOD);
m_smsg->on = TIME_ON;
m_smsg->off = TIME_OFF;
m_timeout = 0;
}
// insert into the neighbor table
call SPNeighbor.insert(&broadcast);
}
----------------------------------------------------------------------------------
4. Recompile and reinstall your application using make tmote lowpower for the changes to take effect.
2010년 1월 10일 일요일
Is this a bug in Moteiv Boomerang MultiHop?
if (parents[i].cost + parents[i].estimate < newparent) {
---------------------------------------------------------------------------
Should "newparent" be "parentestimate" ??
void selectParent() {
int i;
int newparent = m_parent;
uint16_t parentestimate = parents[m_parent].cost +
parents[m_parent].estimate;
// if our parent is invalid, pick the best parent
if (parents[m_parent].addr == MHOP_INVALID_PARENT) {
for (i = 0; i < MHOP_PARENT_SIZE; i++) {
if (parents[i].cost + parents[i].estimate < newparent) {
newparent = i;
parentestimate = parents[i].cost + parents[i].estimate;
}
}
}
// if we have a parent, don't switch unless they're worthwhile
...
2010년 1월 5일 화요일
interface Intercept...
예를 들어 A->B->C->D 와 같이 멀티홉 라우팅을 할 경우
A: sned();
B: intercept();
C: intercept();
D: receive();
와 같이 동작하게 된다.
이 인터페이스는 /opt/tinyos-1.x/tos/interface/Intercept.nc 에 위치하며, 자세한 내용은 해당 파일을 참조하면 된다.
이 인터페이스는 MultihopRoute 라이브러리에서 구현하기 때문에 이 라이브러리로 wiring을 하여 사용하면 된다.
즉,
-----------------------------------------------------------------
configuration Test{
}
implementation {
component LQIMultiHopRouter as multihopM;
TestM.Intercept -> multihopM.Intercept[AM_SURGEMSG];
}
module TestM {
use interface Intercept;
}
implementation {
event result_t Intercept.intercept(...) {
if( LOCAL_ADDRESS == BASE_ADDRESS ) {
if( data > threshhold ) {
Leds.redOn();
}
}
return SUCCESS;
}
}
-----------------------------------------------------------------
와 같은 식으로 구현하면 된다.
intercept 인터페이스에서는 intercept라는 이벤트를 발생시키는데, 이것은 자신에게 전달된 패킷이 도착했다는 것을 알려주는 것이며 이 때, 인수로 넘어온 패킷을 참조하여 데이터를 취합 하는 작업을 수행할 수 있다. intercept 이벤트 핸들러는 성공 여부를 리턴해주어야 하는데
하부에서 이 값에 따라 데이터를 포워딩할지의 여부를 결정한다. 즉 데이터를 취합하는 경우 수신된 데이터를 그대로 포워딩 하는 것이 아니라 자신에 데이터나 다른 노드에서 수신된 데이터들과 함께 취합한 다음 새로운 패킷으로 전송해야하기 때문에 단순한 포워딩이 아닌 Send()함수를 이용해서 전송을 해주어야 한다. 이를 위해 intercept 이벤트 핸들러에서 리턴 값으로 SUCCESS를 할 경우 단순히 포워딩을 하지만 FAIL을 리턴할 경우 포워딩을 안하기 때문에 상위레이어에서 취합한 데이터를 Send함수를 이용해서 전송할 수 있다. 상위에서 데이터 취합을 하면서 SUCCESS값을 넘겨주면 단순 포워딩도 하고 데이터 취합도 하는 것이기 때문에 중복된 데이터가 전송되는 경우가 발생하므로 주의해야 한다.