Embedded System and Wireless Transmission Realization Based on BlueZ Bluetooth Protocol Stack

1 Introduction

With the development of science and technology and social progress, more and more embedded systems are applied to our actual life, which greatly changes our lives. The development of low-cost, high-performance, high-reliability embedded products is becoming a research hotspot. Especially with the development of informatization and networking, there is an increasing need to exchange information with the outside world. The current mainstream data exchange methods are all wired, but there are many deficiencies in wired communication, and wireless communication is incomparably flexible Sex, mobility and extreme scalability are getting more and more widely used.

Bluetooth technology, as a globally unified wireless communication standard, aims to establish a common open standard for low-power, low-cost radio air interfaces and their control software, to further integrate communication and computers, so that portable devices produced by different manufacturers have no wires Or when the cables are connected to each other, they can have interoperability and interoperability in a close range. The application of Bluetooth technology in the wireless interconnection of various smart devices, multimedia terminal communication and home network is also more and more extensive. This article is implemented on the experimental development platform based on an in-depth study of the official Bluetooth protocol stack BlueZ The transplantation of the protocol stack and the file transmission function are also included.

2. BlueZ architecture

BlueZ consists of Host Control Interface (HCI), Bluetooth protocol core, Logical Link Control and Adaptation Protocol (L2CAP), SCO audio layer, other Bluetooth services, user space background processes and configuration Tool composition. Its complete structure is shown in Figure 1 (in addition to applications and hardware for the part provided by BlueZ).


3. The transplantation of BlueZ protocol [2]

The hardware platform involved in this article is Samsung's s3c2410a development board, and the software platform is the Linux operating system with kernel version 2.4.20. In order to implement the Bluetooth protocol stack BlueZ, the following steps can be performed:

(1) Generate cross compiler and create cross compilation environment

(2) Compile and configure the Linux kernel on the experimental development platform

(3) Install BlueZ software package

(4) Compile the Linux kernel on the experimental development platform

(5) Porting to the s3c2410a experimental platform After completing the porting of the Bluetooth protocol stack BlueZ through the above steps, an embedded Bluetooth application development platform is built. The following uses the Bluetooth function library provided by the platform to develop the file transfer function .

4. Realization of file transfer function

After successfully transplanting the Bluetooth protocol stack BlueZ in the above steps, a complete embedded Bluetooth application development platform has been built. This article will use the API functions provided by BlueZ to implement the Bluetooth file transfer function on the RFCOMM layer. The protocol path used is : Radio Frequency (RF)-Baseband and Link Control (BB & LC)-Host Control Interface (HCI)-Logical Link and Adaptation Protocol (L2CAP)-Serial Port Simulation (RFCOMM)-Object Exchange Protocol (OBEX). Its realization is divided into client program and server-side program, the flow chart is shown in Figure 2.


2 reflects the process of transferring a file from the client to the server through Bluetooth to realize the file. The API functions in the protocol stack used and the settings for Bluetooth communication are as follows: (1) int socket (int domain, int type, int protocol ) Create a socket through this function, where the parameter domain indicates the communication protocol family used by the network program. In this experiment, we use the official Bluetooth protocol stack BlueZ, so our domain value AF_BLUETOOTH, type

We use reliable connection-oriented SOCK_STREAM, protocol BTPROTO_RFCOMM that we use to represent serial port emulation.

(2) int bind (int sockfd, struct sockaDDR * my_addr, int addrlen)

This function is a server-side function that implements the binding port function. In our experiment, the parameter my_addr represents a structure that represents local address information. Its rc_family is taken as AF_BLUETOOTH, and its rc_bdaddr is taken as INADDR_ANY that can communicate with any host.

(3) int listen (int sockfd, int backlog)

This function is a server-side function that implements the * port function, and it is exactly the same as the way we use it under ordinary Linux.

(4) int accept (int sockfd, struct sockaddr * addr, int * addrlen)

This function is a server-side function that completes the function of accepting the client's link request and establishing a link with the client.

(5) int connect (int sockfd, struct sockaddr * serv_addr, int addrlen)

This function is the function of the client. It completes the application to establish a link to the server. Similar to the above binding port. The parameter my_addr represents a structure that represents the server address information to be applied for link. Its rc_family is taken as AF_BLUETOOTH, its rc_bdaddr we can take INADDR_ANY that can communicate with any host.

(6) ssize_t write (int fd, const void * buf, size_t nbytes) ssize_t read (int fd, void * buf, size_t nbyte)

These two functions complete the file reading and writing functions, and also complete the server and client communication functions. When completing the communication between the server and the client, the previously established channel is regarded as a file descriptor, as long as the information is read and written into the file descriptor, just like the process of reading and writing to the file.

The above are the main library functions of the protocol stack BlueZ used in the implementation, and its client core code is as follows:

if ((from_fd = open (argv [2], O_RDONLY)) ==-1)

while (bytes_read = read (from_fd, buffer, BUFFER_SIZE))

{/ * A fatal error occurred * / if ((bytes_read ==-1) && (errno! = EINTR)) break; else if (bytes_read> 0) {ptr = buffer;

status = write (s, ptr, strlen (ptr)); memset (buffer, 0, BUFFER_SIZE);}

}

Its server-side core code is as follows: / * Create target file * / memset (buf, 0, BUFFER_SIZE); while (1) {bytes_read = read (client, buf, sizeof (buf));

if (bytes_read> 0)

{ptr = buf; while (bytes_write = write (to_fd, ptr, bytes_read)) {/ * A fatal error occurred * /

if ((bytes_write ==-1) && (errno! = EINTR)) break; / * After writing all the read bytes * / else if (bytes_write == bytes_read) break; / * Only write a part, continue to write * / else if (bytes_write> 0) {ptr + = bytes_write;

bytes_read- = bytes_write;

}} / * Fatal error when writing * / if (bytes_write ==-1) break; / * The buffer must be emptied after reading * / memset (buf, 0, sizeof (buf));

} else {exit (1);}

}

5. Conclusion

At present, there has been very in-depth research on the transplantation of the Bluetooth protocol stack, but there is not much research on the source code level of the Bluetooth protocol stack BlueZ. This paper builds a Bluetooth working environment under the ARM9 + Linux environment, and implements the Bluetooth file transfer function through the library function programming provided by the official Bluetooth protocol stack BlueZ. The use of embedded systems and wireless transmission to achieve file transmission is in line with the development trend of digitalization and networking. The author of this article is innovative: at the source code level, the Bluetooth protocol stack BlueZ is used to implement the file transfer function.

The Emergency Exit Lights Led for business, suitable for residential and commercial illumination, churches, auditoriums, restaurants, supermarkets, warehouse- etc. And the Commercial Exit Sign is a built-in lithium-ion rechargeable battery, more than 90 minutes continuous lighting with the power failure. Also, the li-ion battery pack which can be rechargeable more than 500 times. The exit LED emergency exit lamp meets all requirements for different states and building code for the various installation, you can pass the fire department inspection easily with it.

Lithium Ion Battery Emergency Exit Sign


Lithium Ion Battery Emergency Exit Sign

Emergency Exit Sign With Rechargeable Battery,Customized Arrow Exit Sign,Exit Sign With Running Man

Jiangmen City Pengjiang District Qihui Lighting Electrical Appliances Co., Ltd , https://www.qihuilights.com

Posted on