Design of Home Monitoring System Based on Embedded Linux

Abstract: This article introduces the home monitoring system based on Linux operating system. It uses mobile phone and embedded wireless connection method to fix monitoring equipment (embedded system and camera) to a certain place in the home. When the infrared sensor detects someone, it will be carried out. Take pictures automatically and transfer the photos to the user's mobile phone for effective monitoring.

1 system process architecture

The operating system platform of this system is Linux, the kernel version is 2.6, the target board includes video capture, GPRS module and controller S3C2440. The controller is mainly responsible for providing image data to the customer display and back-end service. The way the video server is started is initiated by the background or trigger. When the user triggers an event, the acquisition program is automatically started or remotely initiated by the user, and then the image data is captured.

2 system design

2.1 Device drivers under Linux

Linux is a free operating system, its source code is public, we can carry out the necessary research and modification according to the needs of the experiment. In the Linux operating system, devices exist in the form of files. The operation of the device is the operation of the file, so that the user can call the general file operation function to access and operate the device. A device driver is an interface between the Linux kernel and an external device. They are executed according to a series of standard function calls by the user. By calling a separate driver, the device of the actual hardware is called to perform a specific operation. The programming interface enables the driver to run independently of the rest of the kernel, just as it is "embedded" into the kernel. This modular design makes the Linux driver easy and efficient to write. The operation is simple and risky, because the device driver is running in the kernel. If there is a problem with the driver writing, it is very likely that the entire Linux system will run into problems. Drivers run differently from normal applications. Drivers can only call their own functions and standard functions in the kernel. Generally, applications can only call application functions such as external databases. Kernel module source files can not include general library files, only kernel functions specified in the kernel can be used, otherwise problems will occur. This is also the difference between the way the driver is written and the way the application is written. The other difference, of course, is that the kernel is different from the way normal applications handle errors:

The error in the application is that it will not cause a system failure, and the debugger can be used to trace the source code to find the problem, but the kernel error may affect the entire system, even if it does not affect the system, it will kill the current The problem with the process, and you can't use debugging to find the source of the problem.

2.2 Infrared Interrupt Trigger Design

The monitoring system realizes the infrared pyroelectric sensor drive and is driven by a character device. Since the S3C2440 has 117 I/O lines. Its I/O line is divided into 8 groups of ports, namely GPA, GPB, GPC, GPD, GPE, GPF, GPG, GPH. When someone enters or leaves the sensed area, the level of the pyroelectric infrared sensor will occur. Change, causing an interruption. The pyroelectric infrared sensor senses that when someone enters, it will automatically start the sleeping video capture device and collect data for the target. At the same time, the driver of the pyroelectric infrared sensor needs to call the interrupt mode to notify the kernel, and let the kernel notify the video collector that it has entered the working state, thereby facilitating device management.

The S3C2440 is configured and controlled by functions and macros on the GPIO pins; the function S3C2440 _ GPIO _ CFGPIN is used to configure the multiplexed GPIO pins; the function SET_ IRQ _ TYPE sets the external interrupt triggers. This monitoring system uses the macro IRQT _ BOTHEDGE to configure the interrupt. The interrupt number is defined in the kernel header file, and each external interrupt is assigned a different interrupt number for control. When the kernel receives an interrupt response, it uses the asynchronous notification method. In order to resolve asynchronous communication of files, the user program must do two things: first, the process must be assigned the "owner"; second, in order to run the asynchronous notification, the user program must set the FASYNC flag in the device. According to the kernel driver, the driver must define its own fasync method. When the program starts to F_SETFL, FASYNC is started and the kernel calls the driver fasync. The kernel space uses an asynchronous signal to send a signal to the user. The corresponding signal function is:

Void kill_fasync(struct fasync_struct **fa,intsig,init band)

The function of the signal function is to trigger the interrupt response when the output level of the infrared sensor changes from high to low or low to high, and the external device obtains a level change generated by the processing function, so that the read method is defined in the driver.

2.3 The video capture driver initializes some default values ​​of the camera in the initialization process. According to the camera command transmitted from the infrared sensor, the camera program is started, the camera is started, the image data is saved in JPEG format, and sent to the mobile terminal Wheel (1) )

{

If(paizhao)

{

_pal=0;

sendPaiZhao() ;

readJPEG() ;

keepData() ;

sendData() ;

}

}

2.4 JPEG compression encoding of image data

In general, uncompressed JPEG image data takes up a large amount of storage space, is very expensive, and is not conducive to network data transmission. Therefore, it is necessary to compress image data. For image compression methods, there are already implementations in the Libjpeg library under Linux. Libjpeg is a standard library under Linux that can be called directly to implement image compression. The main function of this library is to compress the image into a JPEG file format at a certain compression ratio. Since Linux is open source, this library is also open. Not only can work under the general Linux operating system, but also work under embedded Linux. This reduces a lot of underlying work and helps avoid repetitive development efforts.

Before using this library, you first need to install and compile this library. For embedded Linux, the libjpeg library is included in the embedded Linux source code package. This library is added when configuring the relevant library file options, and the kernel can be used to compile the libjpeg library.

The image compression wrapper calls the compress function of the image class as follows:

Int image compress(image *newone, int quality) The function of this function is to compress the image into JPEG format according to the specified quality ratio. The two parameters in the function are pointers to the new image class data (ie, compressed image data), and the other parameter is the specified compression ratio, generally ranging from 0 to 100. The larger the number, the quality of the compressed image. The higher the value, the clearer it is, but the larger the data file size after compression. Therefore, the compression ratio is not as large as possible, and needs to be determined according to the actual needs of the experiment to meet the experimental functional requirements and the storage cost and transmission cost are the minimum standards.

2.5 Sending and receiving short messages

The embedded monitoring system connects to the GPRS by using the serial port, and uses the GPRS module to send and receive short messages. There are two modes for sending and receiving SMS messages, text mode and PDU mode. The text mode can only send flexible ASCII characters. The content of the short message is simple. The biggest shortcoming is that other characters cannot be sent or received. The PDU mode performs new encoding according to a certain format. Generally, the PDU sequence of the hexadecimal number is mainly used, and all Chinese or images are encoded and then sent (see Figure 2-1).

The programming process is as follows:

1) Open the serial port

Opening a serial device file requires the use of standard I/O manipulation functions.

Fd=open("/dev/ttyS0", O_RDWR|O_NDELAY|O_NOCTTY);

2) Set the serial port properties

The serial port has some specified attributes that must be set. Otherwise, it will not work normally. Generally, set the baud rate, control mode flag, local mode flag, input/output mode flag, control characters and other related serial port attributes.

3) Clear the send/receive buffer

In order to avoid the interference of the previous data, the data of the buffer must be emptied before the data can be read into the buffer. The purpose of this is to avoid unnecessary data interference.

4) Read and write data from the serial port

The serial data read/write uses standard read/write functions (read() and write()).

5) Close the serial port

Turn off the serial port for the convenience of using the serial port next time. The function that closes the serial port is the close() function.

2.6 Sending MMS messages

The video subsystem in the Linux system is Video4Linux, which provides a complete, unified API function for the application, and the video application can call the API to complete the operation of the video capture device. The node file for the device is at #mknod/dev/video c810

1) Open the device

Open the device with the open() function.

fVideo=open("dev/video", O_RDWR);

2) Obtain equipment parameters

Ioctl (fVideo, VIDIOCGCAP, &vcap);

3) Set image acquisition parameters

Ioctl (fVideo, VIDIOCGPICT, &vcap);

4) Image acquisition

Ioctl (fVideo, VIDIOCMCAPTURE, &mem);

5) Wait for the acquisition to end. Since the acquisition takes a while, the application needs to have a corresponding waiting period.

Ioctl (fVideo, VIDIOCSYNC, &mem, frame);

6) Write the captured image data to a file

Write_jpeg(buf++mb.offsets[0], mem);

7) Clear memory map

Munmap(but,mb.size) ;

8) Turn off the device

Close(fVideo) ;

After obtaining the image data, the data is encapsulated by MMS. First, the data encapsulation of the MMS header part is added, and then the SMIL part is encapsulated. Here, the MMS related information is mainly specified, and finally each input multimedia information is encoded. . Finally, the information is sent out through the GPRS module.

3 system function test results

This article tests the acquisition, transmission, and display of video data based on the jpeg format standard. The video data is collected by the camera, and the image data is transmitted to the mobile phone after being packaged by GPRS. Infrared senses that when someone enters, the camera takes off the image of the image, and then sends the image to the user's mobile phone through the GPRS module, thus completing the effective monitoring action. (Author: Long Yong)

0 times
Window._bd_share_config = { "common": { "bdSnsKey": {}, "bdText": "", "bdMini": "2", "bdMiniList": false, "bdPic": "", "bdStyle": " 0", "bdSize": "24" }, "share": {}, "image": { "viewList": ["qzone", "tsina", "tqq", "renren", "weixin"], "viewText": "Share to:", "viewSize": "16" }, "selectShare": { "bdContainerClass": null, "bdSelectMiniList": ["qzone", "tsina", "tqq", "renren" , "weixin"] } }; with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share. Baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];