2010년 11월 9일 화요일

Little endian format의 데이터 처리

tinyos-1.x 버전에서는 Listen 이나 기타 시리얼 프로그램을 통해 패킷을 확인하고 분석하는데 요 녀석이 리틀엔디안 포맷이라 실제 데이터를 읽을 때는 바이트 단위로 앞뒤를 뒤집어서(?) 확인해야 한다.
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.