Transmisi Citra Pada Perangkat Jaringan Sensor Visual Nirkabel Platform Imote2 Berbasis IEEE 802.15.4 ZigBee Embedded Linux

Catatan

Abstrak

BAB 1 Pendahuluan

1.1 Latar Belakang

1.2 Rumusan Masalah

1.3 Tujuan Penelitian

1.4 Manfaat Penelitian

1.5 Batasan Masalah

BAB 2 Tinjauan Pustaka

2.1 Penelitian Sebelumnya

2.2 Tinjauan Mutahir (State of The Art)

2.3 Daya Listrik

2.4 Standar IEEE 802.15.4 Zigbee

2.4.1 PHY Layer

2.4.2 MAC Layer

2.4.3 Network Layer

2.4.4 Application Layer

2.5 Intel Mote 2 (Imote2)

2.5.1 Radio Processor Board IPR2400

2.5.2 Interface Board IIB400

2.5.3 Sensor Board IMB400

2.5.4 Power Supply Board IBB2400

2.6 JPEG2000

2.6.1 Codestream syntax

2.6.2 Data Ordering

2.6.3 Arithmetic Entropy Coding

2.6.4 Coefficient Bit Modeling

2.6.5 Quantization

2.6.6 Transform

2.6.7 DC Level, Component Transform

2.6.8 Region of Interest

2.7 Peak Signal to Noise Ratio

BAB 3 Metode Penelitian

3.1 Lokasi dan Waktu Penelitian

3.2 Sumber dan Jenis Data Penelitian

3.3 Instrumen dan Bahan Penelitian

3.4 Tahapan Penelitian

3.4.1 Implementasi IEEE 802.15.4 Zigbee untuk transmisi citra

//************************************************************ 
//
// blocking.c
//
// Gefan Zhang
//
//*************************************************************
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "tosmac.h"
void msg_init(TOS_Msg* pMsg)
{
pMsg->length = 0;
pMsg->fcfhi = 0;
pMsg->fcflo = 0;
pMsg->dsn = 0;
pMsg->destpan = 0;
pMsg->addr = 0;
pMsg->type = 0;
pMsg->group = 0;
memset(pMsg->data, 0, TOSH_DATA_LENGTH);
pMsg->strength = 0;
pMsg->lqi = 0;
pMsg->crc = 0;
pMsg->ack = 0;
pMsg->time = 0;
}
//--------------------- main ------------------------------- int main(int argc, char* argv[])
{
int tosmac_dev;
TOS_Msg recv_pkt;
TOS_Msg send_pkt;
// open as blocking mode
tosmac_dev = open(TOSMAC_DEVICE, O_RDWR);
if (tosmac_dev < 0)
{
fprintf(stderr, "Open error: %s\n", TOSMAC_DEVICE);
return 1;
}
msg_init(&send_pkt);
send_pkt.addr = 99;
// memcpy(send_pkt.data, "DATA for test", 14);
memcpy(send_pkt.data, "0000000000000", 14);
send_pkt.length = 14;
printf("User write to driver\n");
write(tosmac_dev, (TOS_Msg*)&send_pkt, sizeof(TOS_Msg));
// close device
close (tosmac_dev);
return 0;
}
//************************************************************
//
// blocking.c
//
// Gefan Zhang
//
//*************************************************************
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "tosmac.h"
void msg_init(TOS_Msg* pMsg)
{
pMsg->length = 0;
pMsg->fcfhi = 0;
pMsg->fcflo = 0;
pMsg->dsn = 0;
pMsg->destpan = 0;
pMsg->addr = 0;
pMsg->type = 0;
pMsg->group = 0;
memset(pMsg->data, 0, TOSH_DATA_LENGTH);
pMsg->strength = 0;
pMsg->crc = 0;
pMsg->lqi = 0;
pMsg->ack = 0;
pMsg->time = 0;
}
//--------------------- main -------------------------------

int main(int argc, char* argv[])
{
int tosmac_dev;
TOS_Msg recv_pkt;
TOS_Msg send_pkt;
// open as blocking mode
tosmac_dev = open(TOSMAC_DEVICE, O_RDWR);
if (tosmac_dev < 0)
{
fprintf(stderr, "Open error: %s\n", TOSMAC_DEVICE);
return 1;
}
printf("User read from driver:\n");
read(tosmac_dev, &recv_pkt, sizeof(TOS_Msg));// != sizeof(TOS_Msg);
printf("length is %d\n", recv_pkt.length);
printf("data is %s\n", recv_pkt.data);
// close device
close (tosmac_dev);
return 0;
}

3.4.2 Testbed

3.5 Alur Analisis

BAB IV Pembahasan

4.1 Program Transmisi

4.2 Program Pengirim

1 //************************************************************ 
2 //
3 // blocking.c
4 //
5 // Gefan Zhang
6 //
7 //*************************************************************
8 // Modified by : Fajar Purnama
9 #include <stdio.h> 
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <sys/ioctl.h>
13 #include <tosmac.h>
14 void msg_init(TOS_Msg* pMsg) 
15 {
16 pMsg->length = 0;
17 pMsg->fcfhi = 0;
18 pMsg->fcflo = 0;
19 pMsg->dsn = 0;
20 pMsg->destpan = 0;
21 pMsg->addr = 0;
22 pMsg->type = 0;
23 pMsg->group = 0;
24 memset(pMsg->data, 0, TOSH_DATA_LENGTH); // 28 bytes usually
25 pMsg->strength = 0;
26 pMsg->lqi = 0;
27 pMsg->crc = 0;
28 pMsg->ack = 0;
29 pMsg->time = 0;
30 }
31 //---Main-Program---// 
32 int main(int argc, const char *argv[]){
33 // Check Error
34 if(argv[1]==NULL){
35 printf("Usage: ./send_file [file], example: ./send_file_advance image.ppm");
36 return 1;
37 }
38 //sleep(10); //pause for 10 sec (give time for receiver to prepare) cross this out if not needed
39 // Declaration
40 int tosmac_dev, file, file_size, h, i, j, k;
41 //char *packet;
42 TOS_Msg recv_pkt;
43 TOS_Msg send_pkt;
44 // open as blocking mode
45 tosmac_dev = open(TOSMAC_DEVICE, O_RDWR);
46 if (tosmac_dev < 0)
47 {
48 fprintf(stderr, "Open error: %s\n", TOSMAC_DEVICE);
49
50 return 1;
51 }
52 // open file to be send
53 file = open(argv[1], O_RDWR); // open file
54 file_size = lseek(file,0,SEEK_END); // calculate filesize by going to final byte of file using lseek function from fcntl.h
55 lseek(file,0,SEEK_SET); // return to start of file
56 msg_init(&send_pkt);
57 send_pkt.addr = 99; // Address
58 h = file_size/TOSH_DATA_LENGTH; // How much packet or times of transmission should be prepared (using div)
59 i = file_size%TOSH_DATA_LENGTH; // Remainder of "h" (using mod)
60 j = 0;
61 k = 0;
62 while(j+1<h){ // Because j (requested file order) starts at zero 
63 so it's j+1
64 // Use this if need resting time for when k reach certain accumulative bytes //
65 /*if(k%1400==0){
66 sleep(1);
67 }*/
68 read(tosmac_dev, (TOS_Msg*)&recv_pkt, sizeof(TOS_Msg));
69 // Waiting for receiver to send a packet (for ACK), it will wait until receiver is ready
70 j = recv_pkt.data[1]+3000; // Requested order of file in packet, 3000 because it starts at -3000, the data type of data doesn't allow over 3000 while 3300 packet is needed, So we start from below 0.
71 printf("Packet %d/%d\n",j,h); // Verbose
72 k = j*TOSH_DATA_LENGTH; // Packet converted into byte
73 lseek(file,k,SEEK_SET); // Seek to the requested byte
74 read(file,send_pkt.data,TOSH_DATA_LENGTH); // reading 28 byte from file, then read next 28 due to while() loop, file >>>>> send_pkt.data
75 send_pkt.group = 7; // Group identifier, modify this as wished
76 // writing packet to device
77 printf("User writing %d bytes to driver\n", TOSH_DATA_LENGTH);
78 // verbose
79 write(tosmac_dev, (TOS_Msg*)&send_pkt, sizeof(TOS_Msg));
80 // writing to device, (TOS_Msg*)&send_pkt >>>>> tosmac_dev, & it's a pointer
81 k += TOSH_DATA_LENGTH; // accumulative payload sent
82 printf("%d bytes written\n", k); // verbose
83 // use this function if for some reason need to slow down
84 // usleep(30000); // in micro seconds
85 }
86 // Sending the last bytes
87 read(tosmac_dev, (TOS_Msg*)&recv_pkt, sizeof(TOS_Msg));
88 // Waiting for receiver to send a packet (for ACK), it will wait
89 until receiver is ready
90 read(file,send_pkt.data,i); // i = remainder
91 printf("User writing %d bytes to driver\n", i); // verbose
92 write(tosmac_dev, (TOS_Msg*)&send_pkt, i); // final sending
93 k += i; // accumulative payload sent
94 memcpy(send_pkt.data,"0S0T1O1P0",9);
95 write(tosmac_dev, (TOS_Msg*)&send_pkt, 9);
96 printf("%d bytes written, FINISH!!\n", k); // verbose
97 //close device   
98 close(tosmac_dev);
99 close(file);
100 return 0;
101 }

4.1.2 Program Penerima

1 //************************************************************ 
2 //
3 // blocking.c
4 //
5 // Gefan Zhang
6 //
7 //*************************************************************
8 // Modified by : Fajar Purnama
9 #include <stdio.h> 
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include <sys/ioctl.h>
13 #include <tosmac.h>
14 void msg_init(TOS_Msg* pMsg) 
15 {
16 pMsg->length = 0;
17 pMsg->fcfhi = 0;
18 pMsg->fcflo = 0;
19 pMsg->dsn = 0;
20 pMsg->destpan = 0;
21 pMsg->addr = 0;
22 pMsg->type = 0;
23 pMsg->group = 0;
24 memset(pMsg->data, 0, TOSH_DATA_LENGTH); // 28 bytes usually
25 pMsg->strength = 0;
26 pMsg->lqi = 0;
27 pMsg->crc = 0;
28 pMsg->ack = 0;
29 pMsg->time = 0;
30 }
31 //--------------------- main ------------------------------- 
32 int main(int argc, const char *argv[]) {
33 // Check Error
34 if(argv[1]==NULL){
35 printf("Usage: ./recv_file [file], example: ./recv_file_advance image.ppm");
36 return 1;
37 }
38 // Declaration 
39 int tosmac_dev, file, i;
40 TOS_Msg recv_pkt;
41 TOS_Msg send_pkt;
42 // open as blocking mode 
43 tosmac_dev = open(TOSMAC_DEVICE, O_RDWR); // TOSMAC_DEVICE = /dev/tosmac, O_RDWR = Open as Read & Write
44 // Check Error
45 if (tosmac_dev < 0)
46 {
47 fprintf(stderr, "Open error: %s\n", TOSMAC_DEVICE);
48
49 return 1;
50
51 }
50 // file 
51 file = open(argv[1], O_RDWR);
52 // Check Error
53 if(file<0){
54 creat(argv[1], O_RDWR); // create empty file, argv[1] if no file exist: user input (./recv_file argv[1])
55 file = open(argv[1], O_RDWR); // Open created file
56 }
57 // receving file 
58 printf("User read from driver:\n");
59 // receive 28 bytes of file for infinity
60 while(1){
61 // Seek to end of file to continue receive (this feature allows continueable download)
62 i = lseek(file,0,SEEK_END);
63 send_pkt.data[1] = (i/TOSH_DATA_LENGTH)-3000; // Since the max value of data type is 3000 we start from -3000, so we could put a number up to 6000, This feature request tells the transmitter how much bytes already received so the transmitter will sinchronize.
64 write(tosmac_dev, (TOS_Msg*)&send_pkt, sizeof(TOS_Msg)); // sending i in send_pkt.data[1]
65 alarm(2); // 2 seconds timeout
66 read(tosmac_dev, (TOS_Msg*)&recv_pkt, sizeof(TOS_Msg)); // Read receive file from Tosmac Device, Pause if device == NULL, !=sizeof(TOS_Msg)
67 // Stop code, break infinite while loop if this code is received, send application should send this string to tell if transmission finish
68 if(strncmp(recv_pkt.data,"0S0T1O1P0",9)==0){
69 break;
70 }
71 // Use group as identifier, so it will not process packet if it is not on this group
72 if(recv_pkt.group!=7){
73 continue; // it will ignore next code and restart while loop
74 }
75 // Verbose, shows accumulative received number of bytes
76 printf("Receiving %d bytes of data\n", recv_pkt.length);
77 i += recv_pkt.length; // Equal to i = i + recv_pkt.length
78 printf("Received %d bytes\n", i);
79 // Writing received 28 bytes to file that had just been created
80 write(file, recv_pkt.data, recv_pkt.length); // write will automatically go to last byte order of file
81 }
82 printf("FINISH!!"); 
83 // closing device and file
84 close (tosmac_dev);
85 close(file);
86 return 0;
87 }

4.2 Kompilasi Openjpeg

tar xfv linux-gcc-4.1.2-arm-xscale-linux-gnu-glibc-2.3.3.tgz 
tar xfv openjpeg-1.5.1.tar.gz
tar xfv zlib-1.2.8.tar.gz
tar xfv lcms2-2.6.tar.gz
tar xfv libpng-1.2.51.tar.gz
export PATH=/[lokasi folder]/arm-xscale-Linux-gnu/bin/:$PATH
cd /[lokasi folder]/lcms2-2.6 
export CROSS-PREFIX=/[lokasi folder]/arm-xscale-linux-gnu/arm-xscale-linux-gnu/
./configure --prefix=/[lokasi folder]/arm-xscale-Linux-gnu/arm-xscale-Linux-gnu/ --host=arm-xscale-linux-gnu
make && make install
cd /[lokasi folder]/zlib-1.2.8 
CC=arm-xscale-linux-gnu-gcc prefix=/[lokasi folder]/arm-xscale-Linux-gnu/arm-xscale-Linux-gnu/ CFLAGS=”-04” ./configure --shared
make && make install
cd /[lokasi folder]/libpng-1.2.51 
./configure --prefix=/[lokasi folder]/arm-xscale-linux-gnu/arm-xscale-linux-gnu/ --host=arm-xscale-linux-gnu
make && make install
cd /[lokasi folder]/zlib-1.2.8 
CC=arm-xscale-linux-gnu-gcc prefix=/[lokasi folder]/arm-xscale-Linux-gnu/arm-xscale-Linux-gnu/ CFLAGS=”-04” ./configure --shared
make && make install
cd /[lokasi folder]/libpng-1.2.51 
./configure --prefix=/[lokasi folder]/arm-xscale-linux-gnu/arm-xscale-linux-gnu/ --host=arm-xscale-linux-gnu
make && make install
cd openjpeg-1.5.1 
./configure --prefix=/[lokasi folder]/[lokasi folder bebas]/ --host=arm-xscale-Linux-gnu --enable-jpwl --enable-debug --disable-tiff
make && make install

4.3 Implementasi Testbed

4.4 Program Perintah

1 //************************************************************ 
2 //
3 // blocking.c
4 //
5 // Gefan Zhang
6 //
7 //*************************************************************
8 // Modified by Fajar Purnama
9 /* Only Difference from original send.c is an addition of arguement (argc, argv) we could send any message we want without changing its source code for example sending hello message just type ./send_command hello */
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 #include <sys/ioctl.h>
14 #include <tosmac.h>
15 void msg_init(TOS_Msg* pMsg) {
16 pMsg->length = 0;
17 pMsg->fcfhi = 0;
18 pMsg->fcflo = 0;
19 pMsg->dsn = 0;
20 pMsg->destpan = 0;
21 pMsg->addr = 0;
22 pMsg->type = 0;
23 pMsg->group = 0;
24 memset(pMsg->data, 0, TOSH_DATA_LENGTH);
25 pMsg->strength = 0;
26 pMsg->lqi = 0;
27 pMsg->crc = 0;
28 pMsg->ack = 0;
29 pMsg->time = 0;
30 }
31 //--------------------- main -------------------------------
32 int main(int argc, const char *argv[]) {
33 if(argv[1]==NULL){
34 printf("Usage: ./send_command [message], example ./send_command reboot, ./send_command hello\n");
35 return 1;
36 }
37 int tosmac_dev;
38 TOS_Msg recv_pkt;
39 TOS_Msg send_pkt;
40 // open as blocking mode
41 tosmac_dev = open(TOSMAC_DEVICE, O_RDWR);
42 if (tosmac_dev < 0)
43 {
44 fprintf(stderr, "Open error: %s\n", TOSMAC_DEVICE);
45 return 1;
46 }
47 msg_init(&send_pkt);
48 send_pkt.addr = 99;
49 memcpy(send_pkt.data, argv[1], TOSH_DATA_LENGTH);
50 send_pkt.length = TOSH_DATA_LENGTH;
51 printf("User write to driver\n");
52 write(tosmac_dev, (TOS_Msg*)&send_pkt, sizeof(TOS_Msg));
53close(tosmac_dev);
54 return 0;
55 }
1 //************************************************************ 
2 //
3 // blocking.c
4 //
5 // Gefan Zhang
6 //
7 //*************************************************************
8 // Modified by Fajar Purnama
9 /* The only difference is system() function is added from stdlib.h so the message received will be proccess as a command with this code still limited to 28 bytes. Example of message receive is recv_pkt.data = "reboot", it will be system("reboot"), and it will reboot the system */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include <sys/ioctl.h>
15 #include <tosmac.h>
16 void msg_init(TOS_Msg* pMsg)
17 {
18 pMsg->length = 0;
19 pMsg->fcfhi = 0;
20 pMsg->fcflo = 0;
21 pMsg->dsn = 0;
22 pMsg->destpan = 0;
23 pMsg->addr = 0;
24 pMsg->type = 0;
25 pMsg->group = 0;
26 memset(pMsg->data, 0, TOSH_DATA_LENGTH);
27 pMsg->strength = 0;
28 pMsg->crc = 0;
29 pMsg->lqi = 0;
30 pMsg->ack = 0;
31 pMsg->time = 0;
32 }
33 //--------------------- main -------------------------------
34 int main(int argc, char* argv[])
35 {
36 int tosmac_dev;
37 TOS_Msg recv_pkt;
38 TOS_Msg send_pkt;
39 // open as blocking mode
40 tosmac_dev = open(TOSMAC_DEVICE, O_RDWR);
41 if (tosmac_dev < 0)
42 {
43 fprintf(stderr, "Open error: %s\n", TOSMAC_DEVICE);
44 return 1;
45 }
46 printf("User read from driver:\n");
47 read(tosmac_dev, &recv_pkt, sizeof(TOS_Msg));// != sizeof(TOS_Msg);
48 printf("data is %s\n", recv_pkt.data);
49 system(recv_pkt.data);// Process recv_pkt.data as a command in terminal
50 // close device
51 close (tosmac_dev);
52 return 0;
53 }

4.3.2 Penempatan Program

export PATH=/[lokasi folder]/arm-xscale-Linux-gnu/bin/:$PATH (jika belum) 
cd /[lokasi folder program]
arm-xscale-linux-gnu-gcc -Wall send.c -o send
arm-xscale-linux-gnu-gcc -Wall recv.c -o recv
arm-xscale-linux-gnu-gcc -Wall send_command.c -o send_command
arm-xscale-linux-gnu-gcc -Wall recv_command.c -o recv_command
arm-xscale-linux-gnu-gcc -Wall send_file_advance.c -o
send_file_advance
arm-xscale-linux-gnu-gcc -Wall recv_file_advance.c -o
recv_file_advance
ssh 192.168.98.101 
mkdir /root/transmit && mkdir /root/command && mkdir /root/image
quit && exit
ssh 192.168.99.102
mkdir /root/transmit && mkdir /root/command && mkdir /root/image
quit && exit
cd /[lokasi program] 
scp * root@192.168.98.101:transmit/ && scp *
root@192.168.99.102:transmit/
cd /[lokasi folder openjpeg]
scp -r [folder openjpeg] root@192.168.98.101:
scp -r [folder openjpeg] root@192.168.99.102:
ssh 192.168.99.102 
cd /[lokasi folder openjpeg]
cd bin && mv * /bin
cd ../include && mkdir /usr/include && mv * /usr/include
cd ../lib && mv * /lib
cd ../share && mv man /usr/share && mv /doc/* /usr/share/doc
quit && exit
ssh 192.168.98.101
cd /[lokasi folder openjpeg]
cd bin && mv * /bin
cd ../include && mkdir /usr/include && mv * /usr/include
cd ../lib && mv * /lib
cd ../share && mv man /usr/share && mv /doc/* /usr/share/doc
quit && exit
#!/bin/bash 
/root/transmit/send_file_advance /root/image/1.ppm
#!/bin/bash 
image_to_j2k -i /root/image/1.ppm -r 1 -o /root/image/1r1.j2k
/root/transmit/send_command Finish!!
#!/bin/bash 
/root/transmit/send_file_advance /root/image/1r1.j2k
#!/bin/bash 
image_to_j2k -i /root/image/1.ppm -r 5 -o /root/image/1r5.j2k
/root/transmit/send_command Finish!!
#!/bin/bash 
/root/transmit/send_file_advance /root/image/1r5.j2k
#!/bin/bash 
image_to_j2k -i /root/image/1.ppm -r 1 -o /root/image/1r10.j2k
/root/transmit/send_command Finish!!
#!/bin/bash 
/root/transmit/send_file_advance /root/image/1r10.j2k
cd /[lokasi file command] 
scp * root@192.168.98.101:command/
scp * root@192.168.99.102:command/

4.3.3 Konfigurasi Startup

#!/bin/sh 
insmod /lib/modules/2.6.29.1_r1.1/kernel/arch/arm/mach-pxa/ssp.ko
insmod /lib/modules/2.6.29.1_r1.1/kernel/drivers/tosmac/tos_mac.ko
mknod /dev/tosmac c 240 0
while (true)
do
/root/transmit/recv_command
Done

4.3.4 Penggunaan Testbed

/root/transmit/send_command /root/command/A (transmisi citra raw) 
/root/transmit/recv_file_advance /root/image/[nama citra output].ppm
/root/transmit/send_command /root/command/B (kompresi rasio 1)
/root/transmit/recv (tunggu pemberitahuan selesainya kompresi)
/root/transmit/send_command /root/command/C (transmisi citra rasio 1)
/root/transmit/recv_file_advance /root/image/[nama citra output].j2k
/root/transmit/send_command /root/command/D (kompresi rasio 5)
/root/transmit/recv (tunggu pemberitahuan selesainya kompresi)
/root/transmit/send_command /root/command/E (transmisi citra rasio 5)
/root/transmit/recv_file_advance /root/image/[nama citra output].j2k
/root/transmit/send_command /root/command/F (kompresi rasio 10)
/root/transmit/recv (tunggu pemberitahuan selesainya kompresi)
/root/transmit/send_command /root/command/G(transmisi citra rasio 10)
/root/transmit/recv_file_advance /root/image/[nama citra output].j2k
j2k_to_image -i [citra .j2k] -o [nama citra .ppm] 
compare -metric PSNR [citra asli] [citra pembanding] [citra ouput pengukuran]
ps (terlihat nomor proses aplikasi) 
cat /proc/[nomor proses aplikasi]/status

4.4 Analisis Data

4.4.1 Konsumsi Daya Listrik

4.4.2 Waktu Proses Transmisi

4.4.3 Kualitas Citra

4.4.4 Besar File dan Memory

BAB 5 Penutup

5.1 Simpulan

5.2 Saran

Citra

Daftar Pustaka

Mirror

this blog contains all my articles licensed under creative commons attribution customized sharealike (cc-by-sa) where you can sell but mention the open one here

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store