Image Transmission on Wireless Visual Sensor Networking Devices Imote2 Platform Based on IEEE 802.15.4 ZigBee Embedded Linux 2

in blurtech •  4 years ago 

previous

Chapter 3 Research Method

3.1 Location and Time of Research

Observation and data collection were carried out at the Communication Systems Laboratory, Department of Electrical Engineering, Faculty, Udayana University, Jimbaran and in the conference room, GDLN, Sudirman Campus, Udayana University. The research schedule plan starts from the end of May 2014 and must be completed before the end of November 2014, more details are in the Appendix.

3.2 Sources and Types of Research Data

Data sources can be grouped into 2 types:

  1. Primary Data: In the form of power consumption values, memory, and time from the Imote2 WSN device.
  2. Secondary Data: In the form of research schemes, device specifications, and implementation procedures of IEEE 802.15.4 Zigbee on JSVN Imote2 in image transmission.

The types of data are also grouped into 2 types:

  1. Quantitative Data: Is data in the form of numbers, in this study the value of electricity, memory, and time, or the calculation of a value derived from primary data.
  2. Qualitative Data: Data that is not in the form of numbers, in this study is a statement of the performance of the WSVN Imote2 device from various conditions applied. In addition, data in the form of graphics, and the implementation of IEEE 802.15.4 Zigbee in image transmission.

3.3 Research Instruments and Materials

The research instrument can be seen in Table 3.1 - Table 3.5. The Imote2 JSVN device can be seen in Figure 2.10.

Table 3.1 - Table 3.5 Instrument Specifications
NO Instrumen Spesifikasi Fungsi
1 Laptop Intel® Pentium® dual – core processor T4200 (2.0 GHz, 800 MHz FSB, 1 MB L2 cache) Sebagai pemberi perintah dalam transmisi.
Mobile Intel® Graphics Media Accelerator 4500MHD
1GB DDR2
128 WXGA Acer CrystalBriteTM LCD
250GB HDD
Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet Controller
Atheros Communications Inc. AR928X Wireless Network Adapter
Operating System Kali Linux 1 32 bit
2 Perangkat JSVN Imote2 Radio board (IPR2400/IPR2410). Tranceiver sebagai pengirim citra, receiver sebagai penerima citra.
Multimedia Sensor board (IMB400).
Interface board (IIB400).
Power Supply Board (IBB2400).
Sistem operasi Embedded Linux 2.6.29.1 RC 1.1 untuk ARM
Radio board (IPR2400/IPR2410). PXA271 XScale® processor @ [13–416] Mhz. Sebagai perangkat yang melakukan komputasi dan penyedia media komunikasi radio untuk transmisi nirkabel.
Wireless MMX coprocessor.
256kB SRAM, 32MB FLASH, 32MB SDRAM.
Integrated 802.15.4 radio, support for external radios through SDIO and UART. Max data rate 250 Kbps point-to-point.
Integrated 2.4GHz antenna.
Multicolor status indicator LED.
Basic and advanced expansion connectors supporting : 3xUART, I2C, 2xSPI, SDIO, I2S, AC97, USB host, Camera I/F, GPIO.
Mini-USB port for direct PC connection.
Size: 48 mm x 36 mm. PCB thickness 1.75 mm
Multimedia Sensor board (IMB400). Camera
Image resolution up to 640x480 pixels, 30 fps max. RGB, YcbCr or YUV formats.
Hardware image scaling and filtering – automatic exposure, gain, white balance, black level.
Image controls include saturation, hue, gamma, sharpness.
Audio Codec
Sampling rates up to 48kHz, mono.
SNR > 94dB, THD < -80dB
Programmable filters for noise suppression.
PIR Sensor
Maximum range ~ 5m. Detection Angles 80-100 degrees
Interface board (IIB400). Mote connectors 2x Advanced (male/female). Sebagai penghubung antar radio processor board dengan sensor board atau perangkat lainnya.
USB connector mini-B female.
Serial port A virtual UART with RTS/CTS flow control.
Sertial port B virtual UART without hardware flow control.
JTAG port standard 20-pin connector.
Size 48mm x 36mm x 14m. Weight 11g
3 Kabel USB Sebagai penghubung PC dengan JSVNplatform Imote2.
4 Multimeter Sebagai pengukur konsumsi daya listrik.

The research material is an image captured from the camera sensor of the WSVN Imote2 device on May 9, 2014 at the Communication Systems Laboratory, Department of Electrical Engineering, Udayana University with the Portable Pixelmap Graphic (.ppm) format, 480 x 640 pixel resolution in Figure 3.1, with a large file size. 921.6 KB, and IEEE 802.15.4 Zigbee-based transmission media.

Bahan penelitian

Figure 3.1 Research materials

3.4 Research Stages

Overall the research stage consists of 2 stages. The first stage is the procedure for implementing image transmission using IEEE 802.15.4 Zigbee transmission media on the Imote2 WSVN platform with the embedded Linux operating system. The mechanism for transmitting images is explained. The second stage is the testbed to test the performance of WSVN in image transmission. Performance is determined by the power consumption, the time required for transmission, and the amount of memory used. In general, the description of the stages can be seen in Figure 3.2.

Skema dasar penelitian

Figure 3.2 Schematic of the basis of research

3.4.1 IEEE 802.15.4 Zigbee implementation for image transmission

Radio on Imote2 running Linux OS uses the Tosmac driver. Tosmac provides a script for transmit and receive which will be adjusted for image transmission. It can be seen as follows:

//************************************************************ 
// 
// 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

The testbed uses 2 WSVN Imote2 devices where one functions as a transmitter and the other functions as a receiver. At the transmitter, image capture is carried out with the camera sensor. At the transmitter, the image transmission to the receiver is carried out via wireless media based on IEEE 802.15.4 Zigbee. Image capture has been done in previous studies, therefore only observed in compression and transmission. There are 2 types of transmitted images, namely raw images from the capture of the IMB400 sensor and raw images processed based on the JPEG2000 standard with a ratio of 1, 5, and 10 where the ratio is the limiting of the channel capacity. A ratio of 5 means that the number of bits of the compressed image is limited to a maximum of 1/5 of the original number of bits, and a ratio of 10 means that it is limited to a maximum of 1/10 of the number of original bits.

At the time of transmission, the measurement of power consumption, memory, and time is measured at the transmitter. Measurement of electric power consumption using a multimeter with the object of measurement is the battery on the power supply board (IBB2400). The measurement of electric power is done by measuring the voltage drop and current drop, in other words, the difference in the value of electric power before and after the research. In particular, it measures the consumption of electrical power starting from the command for transmission by the computer until the image is transmitted, as well as the time consumption. The measurement of consumption starts from giving commands by the computer, not from the start of image transmission because it also involves aspects of the operating system used, namely embedded Linux. The measurement result data is from one study. Memory based on the display from the terminal when transmitter access. The transmitted image is measured by PSNR. In general, the testbed can be seen in Figure 3.3, Scenarios will be described in the following sections:

Skema testbed

Figure 3.3 Testbed Scheme

  1. Scenario 1
    • Insert images based on research materials into Imote2 (pre-store).
    • Imote2 setup.
    • Measurement of battery voltage and current before transmission.
    • Image transmission from the transmitter to the receiver with a distance of 5 meters can be seen in Figure 3.4 and Figure 3.5.
    • Measurement of virtual memory used by the transmission program.
    • Measurement of the length of time it will take for transmission.
    • Measurement of battery voltage and current after transmission.
    • Measurement of the image PSNR value.
    • The research is repeated with a distance of 10, and 15 meters can be seen in Figure 3.6 - Figure 3.9.
  2. Scenario 2
    • Imote2 setup.
    • Measurement of battery voltage and current before compression.
    • Image compression is performed on the transmitter with a ratio of 1.
    • Measurement of virtual memory used by compression programs.
    • Measurement of how long it takes to compress.
    • Measurement of battery voltage and current after compression.
    • Measurement of battery voltage and current before transmission.
    • Transmission of the image from the transmitter to the receiver at a distance of 5 meters.
    • Measurement of virtual memory used by the transmission program.
    • Measurement of the length of time it will take for transmission.
    • Measurement of battery voltage and current after transmission.
    • Measurement of the PSNR value.
    • The study was repeated with a compression ratio of 5, and 10.
    • Research is repeated at distances of 10, and 15 meters.

Peta lab sistem komunikasi penelitian jarak 5 meter

Figure 3.4 Map of the research communication system lab with a distance of 5 meters

Gambar 3.5 Lab sistem komunikasi penelitian jarak 5 meter

Figure 3.5 Research communication system laboratory with a distance of 5 meters

Peta lab sistem komunikasi penelitian jarak 10 meter

Figure 3.6 Map of a 10 meter distance research communication system lab

Lab sistem komunikasi penelitian jarak 10 meter

Figure 3.7 Research communication system lab 10 meters distance

Peta ruang konferensi penelitian jarak 15 meter

Figure 3.8 Map of the research conference room with a distance of 15 meters

Ruang konferensi penelitian jarak 15 meter

Figure 3.9 Research conference room at a distance of 15 meters

3.5 Analysis Flow

In this section, the research stage will be described in a flowchart diagram in Figure 3.10, Figure 3.11, and Figure 3.12. The overall research is as follows:

  1. Specifies the image transmission procedure.
  2. Preparing raw image to Imote2 which acts as a transmitter for transmission, compression will be done in Imote2.
  3. Conduct research with distances between Imote2 5, 10, and 15 meters for each raw and processed image transmission based on JPEG2000.
  4. Finds the power consumption of each stage of image transmission.
  5. Get the time taken for each stage and the memory used.
  6. From all the data obtained, the optimal scheme is determined.

Alur penelitian 1

Figure 3.10 Research flow 1

Alur Penelitian 2

Figure 3.11 Research Flow 2

Alur Penelitian 2

Figure 3.12 Research Flow 2

Chapter 4 Discussion

Overall, this chapter discusses the image transmission program, Imote2 Linux as a testbed of the compilation of transmission programs and JPEG2000 compression software to giving commands wirelessly to Imote2 which is the sender, and the final part of this chapter is displayed and analyzed the performance of the Imote2 device. From the research results, it turns out that doing compression before transmission is very helpful to lighten the burden of transmission, and interestingly, the compression process itself does not burden the device too much, so it is highly recommended to use compression.

The point of this research is that Imote2 Linux can be used as a testbed. To summarize again, previous research has succeeded in embedding Linux into the JSVN Imote2 platform and transmitting random data, so in this study it is to transmit image data. The program code in section 3.4.1 is a program for sending character data of up to 28 bytes, then displayed on the screen. To send an image in the form of a file, the code must be modified so that the sender side can read and send the file, and on the receiving side can receive and save the file (not limited to being displayed on the screen), it must also be able to transmit files of more than 28 bytes.

The process for enabling Imote2 Linux to function as a testbed is summarized in Figure 4.1. First, making program code, more fully discussed in section 4.1. Then the program is compiled in section 4.2 and section 4.3, and embeded into Imote2, illustration can be seen in Figure 4.2. Finally, Imote2 is configured to be able to receive commands via radio, in other words, after the transmitter is turned on, ready to receive commands, it can be illustrated in Figure 4.3. Commands can be in the form of compressing, or transmitting images as illustrated in Figure 4.4. This is done because the transmitter is powered by batteries (without cables), so communication is only available via radio.

Alur diagram implementasi testbed

Figure 4.1 Flow diagram of testbed implementation

Illustrasi kompilasi dan embed program

Figure 4.2 Illustration of compiling and embedding a program

Illustrasi ketika startup 1 Illustrasi ketika startup 2

Figure 4.3 Illustration at startup

Illustrasi testbed 1 Illustrasi testbed 2 Illustrasi testbed 3 Illustrasi testbed 4

Figure 4.4 Illustration of the testbed

4.1 Transmission Program

Radio transmission on Imote2. In the previous study described in section 2.1, using the driver from Tosmac to run the radio on Imote2 Linux, here still use the same driver. For transmission, two programs are needed, namely the program for sending and receiving. Both programs are written in C language. Specifically, this research follows the provisions of the tosmac header, namely the maximum data payload sent is 28 bytes. Overall on the sender side reads the image file to be sent, the receiver will create a new file and write the received data to the file. The delivery is done in stages by breaking 28 bytes of each tile (not all at once).

4.2 Sending Program

The following syntax shows a sending program with the file name "send_file_advance.c" which was carried out in this study and is described as follows:

1 //************************************************************ 
2 // 
3 // blocking.c 
4 // 
5 // Gefan Zhang 
6 // 
7 //************************************************************* 
8 // Modified by : Fajar Purnama 

Lines 1 - 8 are comments containing information about the programmer and the modifier. Comments can be marked with "//" or begin with "/ " and end with " /" (which is not bold). Line 5 is the first author of the program, while line 8 is the name of the author who modified the program.

9 #include <stdio.h> 
10 #include <fcntl.h> 
11 #include <unistd.h> 
12 #include <sys/ioctl.h> 
13 #include <tosmac.h>

Lines 9 - 13 indicate the header used in this program, the header contains the code definition used. To use the header, you can use the character "#", this character indicates the script required by the program. On line 9 there is “stdio.h” which is the basic header for all C language programs which defines the “printf” command for displaying to the screen, “while” for looping, arithmetic operations, and many others. Line 10 "fcntl.h" defines the command "open" to open a file and "close" to close and "create" to create, line 11 "unistd.h" defines the command "read" to read the file and "write" to write data to file, and line 13 "tosmac.h" sets the variable in the tosmac (radio) driver.

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 } 

Lines 14 - 30 are written in the form of the function "msg_init" which is a function to initialize the package variables such as address, group, and payload contained in the header "tosmac.h" for transmission.

Inti program “int main” dimulai dari baris 32.

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; 

Lines 33 - 37 contain error checks if the command entered does not match, lines 39 - 43 are part of the variable declaration, lines 44 - 51 open the radio, lines 52 - 55 open the file, and lines 56 - 61 specify packets. On line 32 "int main" there is "int argc, int argv []" so that the program can be executed by selecting the desired file "./send_file_advance argv [1]", as defined on line 53 "file = open (argv [1 ], O_RDWR) ”. If there is no input, it will show how to use the program on line 35, namely "./send_file_advance file" which is set in the statement "if (argv [1] == NULL)" line 34, and line 36 "return 1" to provide an error code on the program if the input matches the statement line 34. Line 45 "tosmac_dev = open (TOSMAC_DEVICE, O_RDWR)" is to open the radio where "TOSMAC_DEVICE" is "/dev/tosmac" as defined in "tosmac.h", "O_RDWR" so that files opened, read & write, can be seen in "fcntl.h". Line 55 "file_size = lseek (file, 0, SEEK_END)" to find the file size by going to the last bit of the file to return it to the initial bit with the code "lseek (file, 0, SEEK_SET)". Defined packets to be sent are "TOS_Msg send_pkt" (line 42) and received "TOS_Msg recv_pkt" (line 43), where "TOS_Msg" is the packet structure defined in "tosmac.h". Line 57 "send_pkt.addr = 99" specifies that the address of the sender is 99. Line 58 "h" is the number of packets by dividing the file size by the maximum data payload "TOSH_DATA_LENGTH", here is 28, while the value "i" (line 59) is the remainder of the division of "h" which is the last byte to be sent.

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 

Lines 62 - 85 are the process transmission and lines 85 - 96 are the last transmissions. The transmission process is contained in line 62 of the while loop, where files are sent every 28 bytes. Looping will stop if "j" reaches the value "h" (number of packets). Before transmission awaits information from the receiver containing the number of packets received on line 68 "read (tosmac_dev, (TOS_Msg *) & recv_pkt, sizeof (TOS_Msg))" (this code will read data received by radio "tosmac_dev" of "sizeof (TOS_Msg) "Which is then written to the pointer "&recv_pkt"). The value contained in “recv_pkt” will be entered into “j” (line 70). The arithmetic operation on “k” (line 72) converts the number of packets to the number of bytes received. After that it will go to the next byte which will be sent on line 73 "lseek (file, k, SEEK_SET)". Then On line 75, sizeof (TOS_Msg)) "(this code will write "&send_pkt "of" sizeof (TOS_Msg) "to" tosmac_dev"). After the while loop is sending the last byte "i" which is the remainder of the division of "j", the last one will send the code "0S0T1O1P0" to the receiver to notify that the transmission has ended.

97 //close device   
98 close(tosmac_dev); 
99 close(file);  
100 return 0; 
101 } 

Lines 97 - 101 radio and file closings and the end of the program, the code "close" to close the file defined in "fcntl.h".

4.1.2 Receiving Program

The following syntax shows the receiving program with the file name "recv_file_advance.c" which was carried out in the study and overall the receiving program is similar to the sending program, in other words only a slight difference can be explained as follows:

1 //************************************************************ 
2 // 
3 // blocking.c 
4 // 
5 // Gefan Zhang 
6 // 
7 //************************************************************* 
8 // Modified by : Fajar Purnama

Lines 1 - 8 are comments containing information about the programmer and the modifier.

9 #include <stdio.h> 
10 #include <fcntl.h> 
11 #include <unistd.h> 
12 #include <sys/ioctl.h> 
13 #include <tosmac.h>

Lines 9 - 13 indicate the header used in this program, the header contains the code definition used.

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 } 

Lines 14 - 30 are functions for initializing the variables in the packet to be transmitted.

The core of the program starts at line 32.

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 } 

Lines 33 - 37 contain error checks if the command entered does not match.

38 // Declaration 
39 int tosmac_dev, file, i; 
40 TOS_Msg recv_pkt; 
41 TOS_Msg send_pkt; 

Lines 38 - 41 are part of the variable declaration.

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 } 

Lines 42 - 49 open the radio.

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 } 

Lines 50 - 56 open the file in this section if no file is found it will create a new file with the "creat" function line 54.

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 } 

Lines 60 - 81 represent the transmission process. In the process of transmitting in an infinite while loop, initially read the number of bytes that have been received by the file (file size) on line 62 "lseek (file, 0, SEEK_END)" and at the same time go to the end of the file. On line 63 the file size is entered into "send_pkt.data [1]" and on line 64 it is sent to the transmitter to tell which bytes should be sent. In this program the value starts from -3000 in order to determine a larger value because the maximum value is approximately 3000 while the value that needs to be sent is more than 3000. To do this there needs to be a change to "tosmac.h" in the packet definition section in the section . For this program the data type "data" changes from "s8" to "s16", the change is to increase the number of bits used. If this is set the maximum value in "send_pkt.data [1]" is only below 1000. All this is done so that the transmission can be resumed if it breaks and suppresses errors. This program is filled with "alarm (2)" on line 65, meaning the program will stop (time out) if 1 while loop exceeds 2 seconds. If this occurs the transmission can be resumed by running the program again showing the same file. Another difference is on line 72 "if (send_pkt.group =! 7) {continue;}" which means if the packet received is not a group 7 to ignore and continue to the next loop. In line 68 "if (strncmp (recv_pkt.data," 0S0T1O1P0 ", 9) == 0) {break;}" means if the received string is "0S0T1O1P0" and the number of characters is "9" then break the while loop, it is determined that the string this is a sign that the transmission has ended.

82 printf("FINISH!!"); 
83 // closing device and file 
84 close (tosmac_dev); 
85 close(file); 
86 return 0; 
87 }

Lines 82 - 87 close radio and file and end of program.

4.2 Openjpeg Compilation

This section contains ways to compile the Openjpeg-1.5.1 software onto Imote2-Linux, in order to make the compression software available on the device. The compiler used is linux-gcc-4.1.2-arm-xscale-linux-gnu-glibc-2.3.3 with dependencies lcms2, libpng, and zlib, for here lcms2-2.6, libpng-1.2.51, and zlib-1.2.8.

The source obtained is compressed in gunzip tape archive format. The following command to extract the compressed file contents:

Lines 60 - 81 represent the transmission process. In the process of transmitting in an infinite while loop, initially read the number of bytes that have been received by the file (file size) on line 62 "lseek (file, 0, SEEK_END)" and at the same time go to the end of the file. On line 63 the file size is entered into "send_pkt.data [1]" and on line 64 it is sent to the transmitter to tell which bytes should be sent. In this program the value starts from -3000 in order to determine a larger value because the maximum value is approximately 3000 while the value that needs to be sent is more than 3000. To do this there needs to be a change to "tosmac.h" in the packet definition section in the section. For this program the data type "data" changes from "s8" to "s16", the change is to increase the number of bits used. If this is set the maximum value in "send_pkt.data [1]" is only below 1000. All this is done so that the transmission can be resumed if it breaks and suppresses errors. This program is filled with "alarm (2)" on line 65, meaning the program will stop (time out) if 1 while loop exceeds 2 seconds. If this occurs the transmission can be resumed by running the program again showing the same file. Another difference is on line 72 "if (send_pkt.group =! 7) {continue;}" which means if the packet received is not a group 7 to ignore and continue to the next loop. In line 68 "if (strncmp (recv_pkt.data," 0S0T1O1P0 ", 9) == 0) {break;}" means if the received string is "0S0T1O1P0" and the number of characters is "9" then break the while loop, it is determined that the string this is a sign that the transmission has ended.

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 

The following command adds the location of the compiler executable file:

export PATH=/[lokasi folder]/arm-xscale-Linux-gnu/bin/:$PATH

The first additional dependencies requested are lcms2.

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 

Command "cd" to go to the folder, "export" to assign a value to a variable, here "CROSS-PREFIX" is defined in the "configure" file on zlib, if compiled for cross-compiler it is given the value of the cross-compiler location. In the file "configure" there is a series of configuration, when executed will be created "Makefile" to compile as needed. Command "--prefix" to add the installation location. Command "make" to compile based on files "Makefile" and "make install" to put the compilation into place according to "--prefix". Next compile zlib for the compiler:

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 

In this research, we need the command "--shared" so that it can be detected by "libpng" during configuration. After that compile libpng:

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 

Command "cd" to go to the folder, "export" to assign a value to a variable, here "CROSS-PREFIX" is defined in the "configure" file on zlib, if compiled for cross-compiler it is given the value of the cross-compiler location. In the file "configure" there is a series of configuration, when executed will be created "Makefile" to compile as needed. Command "--prefix" to add the installation location. Command "make" to compile based on files "Makefile" and "make install" to put the compilation into place according to "--prefix". Next compile zlib for the compiler:

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 

In this research, we need the command "--shared" so that it can be detected by "libpng" during configuration. After that compile libpng:

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 

Based on the file "configure" "--host" determines the type of compilation platform, here is "arm-xscale-linux-gnu", it is necessary to "export" the cross-compiler executable location at the beginning of this section. Lastly is the Openjpeg compilation:

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 Testbed Implementation

Overall, this section contains the transmission process for this study. Initially including the transmission program and Openjpeg so that in essence the device can transmit on a battery or without being connected to a computer.

4.4 Command Program

Here there are additional programs, apart from using the "recv" program, 2 additional programs are needed, namely a program to send commands and a program to receive commands. The program sending the command "send_command.c" is as follows:

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 }

The entire description of the command-sending program is the same as that of the transmission program. In particular, what is different in this program is on line 49 where the characters to be written to "send_pkt.data", namely "argv [1]" will be sent. This program is limited to sending characters up to 28 bytes. Here is the program for receiving the command "recv_command.c":

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 }

The overall description of the receiving program is the same as the description of the transmission program. In particular, what is different about this program is that on line 49 the received characters contained in "recv_pkt.data" will be treated as commands. This is made possible by the “system” function defined in “stdlib.h”.

4.3.2 Program Placement

After the program code is finished, the code is compiled using “arm-xscale-linux-gnu-gcc”.

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  

Then placed in Imote2 in the directory "/root/transmit". The receiver is connected on USB0 with an IP address on the computer 192.168.98.100 and on Imote2 192.168.98.101. The transmitter is connected on USB1 with an IP address on the computer 192.168.99.100 and on Imote2 192.168.99.102. The connection between Imote2 uses SSH (secure shell) which has been prepared in previous studies as described in Chapter 2 section 2.1. Before placing the directory first.

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  

Command "mkdir" (make directory) to create a new folder. For this research, the raw image (Figure 3.1) is contained in the directory "/root/image" under the name "1.ppm". When the directory is ready then the program is entered, as well as the compiled Openjpeg.

cd /[lokasi program] 
scp * [email protected]:transmit/ && scp *  
[email protected]:transmit/ 
cd /[lokasi folder openjpeg] 
scp -r [folder openjpeg] [email protected]: 
scp -r [folder openjpeg] [email protected]: 

SCP is a command to copy data via SSH, "*" indicates all files in that folder, "-r" to copy a directory. Next, the compiled Openjpeg will be placed in the appropriate directory.

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 /[openjpeg folder location] 
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 

To facilitate transmission several commands are prepared in the form of a file as follows:

  1. The following contains the command for sending a raw image with the file name "A":

#!/bin/bash
/root/transmit/send_file_advance /root/image/1.ppm
```

  1. The following contains commands for compressing raw images to JPEG2000 format with a ratio of 1 with the file name "B":

#!/bin/bash
image_to_j2k -i /root/image/1.ppm -r 1 -o /root/image/1r1.j2k
/root/transmit/send_command Finish!!
```

  1. The following contains the command for sending a ratio 1 JPEG2000 image with the file name “C”:

#!/bin/bash
/root/transmit/send_file_advance /root/image/1r1.j2k
```

  1. The following contains commands for compressing raw images to JPEG2000 format with a ratio of 5 with the file name "D":

#!/bin/bash
image_to_j2k -i /root/image/1.ppm -r 5 -o /root/image/1r5.j2k
/root/transmit/send_command Finish!!
```

  1. The following contains the command for sending a 5 ratio JPEG2000 image with the file name “E”:

#!/bin/bash
/root/transmit/send_file_advance /root/image/1r5.j2k
```

  1. The following contains commands for compressing raw images to JPEG2000 format at a ratio of 10 with the file name "F":

#!/bin/bash
image_to_j2k -i /root/image/1.ppm -r 1 -o /root/image/1r10.j2k
/root/transmit/send_command Finish!!
```

  1. The following contains the command for sending a 10 ratio JPEG2000 image with the file name “G”:

#!/bin/bash
/root/transmit/send_file_advance /root/image/1r10.j2k
```

  1. For files "B", "D", "F", after compression will send the characters "Finish !!" to notify the receiver that compression is complete.

Files from the table above will be placed in the directory “/root/command”.

cd /[command file location] 
scp * [email protected]:command/  
scp * [email protected]:command/ 
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE BLURT!