CN102455969B - Method for recording Linux serial communication log - Google Patents
Method for recording Linux serial communication log Download PDFInfo
- Publication number
- CN102455969B CN102455969B CN201010588992.6A CN201010588992A CN102455969B CN 102455969 B CN102455969 B CN 102455969B CN 201010588992 A CN201010588992 A CN 201010588992A CN 102455969 B CN102455969 B CN 102455969B
- Authority
- CN
- China
- Prior art keywords
- serial communication
- data
- application layer
- linux
- log
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Abstract
The invention provides a method for recording a Linux serial communication log. The method comprises the step of establishing a data channel for interaction with an application layer in a Linux core, thereby obtaining detailed information of a serial communication process in the Linux core layer, mainly comprising serial communication actions, serial communication data and the like. The method for recording the Linux serial communication log provided in the invention is to perform processing mainly in the Linux core layer, so that a reliable log function in the serial communication process can be realized without affecting the serial communication. In addition, a plurality of interfaces are provided in the application layer, so that appropriate data channel type, log time accuracy, continuous time interval and log recording proposal can be selected according to actual application requirements and characteristics; therefore, the recorded serial log has higher reliability and readability and is capable of meeting the requirements of different application scenes.
Description
Technical field
The present invention relates to serial communication field, especially a kind of method of Linux serial communication log record.
Background technology
Along with the application of computer system and the development of microcomputer network, computing machine and extraneous message exchange more and more seem important.Serial communication is the transmission information of on a transmission line, and transmission line used is few, and can carry out information transmission by ready-made telephone network.Therefore, serial communication is particularly suitable for remote data transmission.
As shown in Figure 1, on industrial computer or pc machine, may have a plurality of serial ports, each serial ports is connected with terminal string jaws equipment respectively, has formed like this syndeton of one-to-many.Each terminal string jaws equipment is connected with the serial ports on industrial computer or pc machine by serial ports, and then carries out serial communication with industrial computer or pc machine.
In actual serial communication application, in order to check the reliability of serial communication process, often need in the situation that not affecting serial ports proper communication, the information of the process of serial communication (comprising serial communication data, serial communication action etc.) to be recorded in the mode of daily record.Yet under Linux platform, the data in serial communication process have " uniqueness ", after referring to that a serial communication completes here, serial communication data etc. will be emptied and cannot preserve by kernel.
If in the concrete application program of serial communication, the data in advance of serial communication is copied to portion, like this, can affect the efficiency of serial communication on the one hand, this scheme itself does not possess any portability on the other hand, that is to say, once the application program of serial communication, change, serial ports journal function just need to exploitation again in application program.
In serial communication process, linux kernel may become very little data segment serial communication Data Segmentation, if according to this raw data format record, can make daily record readability become poor on the one hand, be not inconsistent with the real time node of serial communication data on the other hand.
Summary of the invention
For these reasons, the present invention is intended to by setting up with application layer and carry out mutual data channel in linux kernel, and then can pass through data channel in application layer, learn that the mode of serial communication process in linux kernel layer realizes the record of serial communication log.
General plotting of the present invention is in the situation that not affecting normal serial communication process, in inner nuclear layer, set up with client layer and carry out mutual data channel, and then in application layer, pass through the information that this data channel obtains serial communication process in linux kernel layer, thereby reach the object of block port communications process.And in application layer, provide configuration interface, made to select suitable data channel mode by application layer, thereby meet the different demands of actual application environment.
A kind of method that the object of this invention is to provide serial communication log record, the time precision of this log recording is in application layer, to be configured according to the different demands in actual application environment, accuracy rating is millisecond (ms)~microsecond (μ s).Specifically according to the practical situations of serial communication data, in application layer, provide a time interval interface that can configure, when in the situation that the time interval of two the same class communication datas in front and back be less than interval setup time, these two communication datas are recorded as to one, thereby greatly improve the readability of serial communication log file, and more identical with actual serial communication.
The technological means that the present invention adopts is: the present invention by setting up with application layer and carry out mutual data channel in linux kernel, and then in application layer by the data channel of having set up, obtain the details of serial communication process in linux kernel layer, mainly comprise serial communication action and serial communication data etc.The method of its realization comprises the following steps:
1) set up three data channel: procfs, sysfs and the netfilter (step S1) communicating by letter between linux kernel layer and Linux application layer;
2) data in serial communication process etc. are kept in the buffer memory of linux kernel layer (step S2);
3) application layer process, according to the option and installment of data channel in application layer, communicates by suitable data channel and kernel, thereby obtain, is kept at the serial communication data (step S3) in linux kernel layer buffer memory;
4) application layer process, according to the configuration in daily record time precision, the time interval in application layer, is further analyzed processing (step S4) by the serial communication data that obtain;
5) application layer process, according to log recording scheme selected in application layer, is written to (step S5) in journal file by the daily record data of handling.The invention provides three kinds of log recording modes: the journal mode of 1. not limitting journal file capacity; 2. limit the cycle index mode of journal file max cap.; 3. limit the multifile journal mode of single log file size.All above-mentioned log recording modes can be selected in application layer configuration.
Of the present inventionly at useful technique effect, be: the serial communication log recording method the present invention relates to is mainly processed in linux kernel layer, can, in the situation that not affecting serial communication, realize a kind of reliable journal function to serial communication process like this.And, a plurality of interfaces are provided in application layer, therefore can be according to actual application demand and feature, select suitable data channel type, daily record time precision, continuous time interval and log recording scheme, thereby make the serial ports daily record of record there is higher reliability and readability, meet the demand of different application scene.Wherein, the most typical application scenarios of the present invention is linux system higher to serial communication reliability requirement and that carry out a large amount of serial communications, as intelligent transportation system.
Accompanying drawing explanation
Fig. 1 serial communication procedure structure block diagram;
Fig. 2 is the process flow diagram that linux kernel layer of the present invention is communicated by letter with application layer data;
Fig. 3 is the process flow diagram that the present invention limits the cycle index mode of journal file max cap..
Embodiment
In order to make object of the present invention, technical scheme and beneficial effect clearer, below in conjunction with drawings and Examples, the present invention is further elaborated.Should be appreciated that specific embodiment described herein, only in order to explain the present invention, is not intended to limit the present invention.
The explanation of nouns of the relevant technical terms the present invention relates to:
Data channel: be a kind of a series of interfaces of carrying out between linux kernel layer and application layer data communication function etc. of realizing.The data channel relating in the present invention mainly contains procfs, sysfs, tri-kinds of modes of netfilter.
Procfs: be process filesystem.It provides the operation that mode that user be take file system is access system kernel data that interface is provided, and user and application program can obtain by proc the information of system, and can change some parameter of kernel.
Sysfs: be at a kind of Virtual File System.It provides the interface of the equipment (device) of accessing in application layer in inner nuclear layer and (driver) information of driving.
Netfilter: be the integrated IP packet filtration system of linux kernel.It provides is interrupting under environment the mode of process communication between inner nuclear layer and application layer.
The present invention by setting up the data channel communicating with application layer in linux kernel, and then in application layer by the data channel of having set up, obtain the mode of the details (mainly comprising serial communication action and serial communication data etc.) of serial communication process in linux kernel layer, realize the efficient and true and reliable log recording of serial communication process under Linux platform.
Specific embodiment of the invention needs combining closely of linux kernel layer and Linux application layer, below in conjunction with accompanying drawing 2, principle of work flow process of the present invention is described further.
1) first, linux kernel will be set up three data channel in initialization procedure---procfs, sysfs and netfilter (step S1), in order to set up and to contact reliably between inner nuclear layer and application layer, the method of setting up data channel is mainly in kernel, to register a series of interface function, can realize like this information that obtains the serial communication process in inner nuclear layer in application layer by some specific system call.
2) then, linux kernel can be kept at all information in serial communication process (comprising serial communication data and serial communication action etc.) in the specific data structure in linux kernel layer buffer memory (step S2).
After the preliminary work of linux kernel completes, in Linux application layer, need to carry out following steps:
3) application layer process, according to the option and installment of data channel in application layer, communicates by suitable data channel and kernel, thereby obtain, is kept at the serial communication data (step S3) in linux kernel layer buffer memory, specifically comprises the following steps:
(3.1) read in configuration file (step S301): Linux application layer program is read in configuration file, according to the content of configuration file, determine the time precision of the data channel of employing, log recording, to log recording file, carry out the time interval of write operation and the recording mode of daily record.
(3.2) select data channel (step S302): according to the config option that reads in data channel in configuration file, select corresponding data channel (providing three kinds of data channel to select in inner nuclear layer: procfs, sysfs and netfilter).
(3.3) read in serial data (step S303): Linux application layer program, by the data channel of selecting in step S302, is read in serial communication procedural information from inner nuclear layer, and the kernel data reading in is left in client layer.
4) application layer process, according to the configuration in daily record time precision, the time interval in application layer, is further analyzed processing (step S4) by the serial communication data that obtain, and specifically comprises the following steps:
(4.1) before and after judgement, whether the data type of two records is all read operation, if not, directly jump into next step (step S402); If, two serial data time intervals (step S401) before and after processing: in serial communication process, linux kernel may become very little data segment serial communication Data Segmentation, if according to this raw data format record, can make daily record readability become poor on the one hand, not be inconsistent with the real time node of serial communication data on the other hand.Therefore, the present invention provides the option in a configurable time interval in application layer, and application layer process can, according to the difference of actual application environment, select the suitable time interval as threshold value.When the time interval of the serial communication data of two same types is less than the condition of described threshold value before and after meeting, these two communication datas are recorded as to one; Otherwise they are recorded as to two.Like this, can improve on the one hand the readability of serial communication log file, on the other hand can be so that the actual conditions of the timing node in serial communication log and serial communication be more identical.
(4.2) precision switching time (step S402): according to reading in the time precision in configuration file in step S301, convert the time in the kernel serial communication data of reading in step S303 to corresponding time precision.
(4.3) deal with data form (step S403): according to the actual requirements, serial communication data-switching is become to suitable form (as sexadecimal etc.).
5) application layer process, according to log recording mode selected in application layer, is written to (step S5) in journal file by the daily record data of handling.Specifically, according to the config option of the log mode in configuration file in step S301, according to corresponding mode, the data after conversion are written in journal file.
Due in actual applications, the data volume of serial communication may be very large, and serial communication data this in validity after longer a period of time, can reduce.If just all communication logs are simply write in certain file, may be subject to the restriction in available memory device space after a period of time; In addition, if crossing conference, individual log file brings very large trouble to searching useful information in daily record.For these reasons, the invention provides three kinds of log recording modes:
1. do not limit the journal mode of journal file capacity: all data are write to journal file in order, and journal file does not have ceiling restriction;
2. limit the cycle index mode of journal file max cap.: serial data is write to journal file, and configuration is upper prescribes a time limit when journal file surpasses, and the stem from journal file is started to continue;
3. limit the multifile journal mode of single log file size: all data are write to journal file in order, and it is in limited time upper that the size in current journal file surpasses configuration, and remaining data are write in a new journal file.
Below in conjunction with accompanying drawing 3, the cycle index mode that limits journal file max cap. of take illustrates its workflow as example.
The cycle index mode of restriction journal file max cap. will record the current lower less important position that writes this daily record in the first row of journal file.First, whether the first trip that judges current journal file effectively (step S501), if invalid, can empty current journal file, newly-built journal file (step S502 ').Then determine this log file location that should write (step S502), judgement is inserted after new log content in this position, whether new log file size surpasses the log file size upper limit (step S503) of configuration, if surpassed, jumps to journal file head and continues to write journal file (step S504); Otherwise, from this position, continue to write (step S504 ').Finally, at this, complete and write after log content, need to upgrade the log file location (step S505) that should write next time.The present invention combines closely by linux kernel layer and Linux application layer, realizes the safe and reliable log recording of serial ports log communication under Linux platform.
The foregoing is only preferred embodiment of the present invention, not in order to limit the present invention, all any modifications of making within the spirit and principles in the present invention, be equal to and replace and improvement etc., within all should being included in protection scope of the present invention.
Claims (9)
1. the method for Linux serial communication log record, it is characterized in that, by setting up with application layer and carry out mutual data channel in linux kernel, and then in application layer, by the data channel set up, obtain the data message of serial communication process in linux kernel layer, these data messages are treated and be written in journal file and obtain serial communication log, the option in a configurable time interval is provided in application layer, application layer process is according to actual application environment, configure a time interval as threshold value, and using this threshold value and should be recorded as one or two as the serial communication data recording of two same types before and after judgement.
2. the method for claim 1, is characterized in that, in linux kernel, set up with application layer between the data channel of communicating by letter comprise three passage: procfs, sysfs and netfilter.
3. method as claimed in claim 2, is characterized in that, the data message in serial communication process is kept in the buffer memory of linux kernel layer.
4. method as claimed in claim 3, is characterized in that, application layer process communicates according to selected data channel and kernel in application layer configuration, thereby is kept at the serial communication data message in linux kernel layer buffer memory described in obtaining.
5. method as claimed in claim 4, is characterized in that, the step that described acquisition is kept at the serial communication data message in linux kernel layer buffer memory comprises:
(1) read in configuration file: Linux application layer program is read in configuration file, according to the content of configuration file, determine the time precision of the data channel of employing, log recording, to log recording file, carry out the time interval of write operation and the mode of log recording; (2) select data channel: according to the config option that reads in data channel in configuration file, select corresponding data channel;
(3) read in serial data: Linux application layer program, by the data channel of selecting in step (2), is read in serial communication procedural information from inner nuclear layer, and the kernel data reading in is stored in client layer.
6. method as claimed in claim 4, it is characterized in that, before and after judgement, whether the data type of two records is all read operation, if, application layer process selects the corresponding time interval as threshold value according to actual application environment in application layer configuration, when the time interval of the serial communication data of two same types in front and back is less than described threshold value, these two communication datas are recorded as to one; Otherwise they are recorded as to two.
7. method as claimed in claim 6, is characterized in that, before and after judgement, whether the data type of two records is all read operation, if not; Or after completing the judgement and the record whether above-mentioned time interval to the serial communication data of two same types be less than described threshold value, application layer process is according to selected data layout and time precision in application layer configuration, and conversion is kept at the data layout of the serial communication data message in linux kernel layer buffer memory and obtains the time precision of data message.
8. method as claimed in claim 7, is characterized in that, application layer process, according to the mode of log recording selected in application layer configuration, is written to the daily record data of handling in journal file.
9. the method as described in claim 5 or 8, is characterized in that, the mode of described log recording comprises three kinds:
1. do not limit the journal mode of journal file capacity: all data are write to journal file in order, and journal file does not have ceiling restriction;
2. limit the cycle index mode of journal file max cap.: serial data is write to journal file, and configuration is upper prescribes a time limit when journal file surpasses, and the stem from journal file is started to continue;
3. limit the multifile journal mode of single log file size: all data are write to journal file in order, and it is in limited time upper that the size in current journal file surpasses configuration, and remaining data are write in a new journal file.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010588992.6A CN102455969B (en) | 2010-12-15 | 2010-12-15 | Method for recording Linux serial communication log |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201010588992.6A CN102455969B (en) | 2010-12-15 | 2010-12-15 | Method for recording Linux serial communication log |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102455969A CN102455969A (en) | 2012-05-16 |
CN102455969B true CN102455969B (en) | 2014-07-16 |
Family
ID=46039176
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201010588992.6A Active CN102455969B (en) | 2010-12-15 | 2010-12-15 | Method for recording Linux serial communication log |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102455969B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104484184A (en) * | 2014-12-26 | 2015-04-01 | 上海斐讯数据通信技术有限公司 | Shell design method of embedded system |
CN105760318B (en) * | 2016-02-16 | 2019-03-08 | 烽火通信科技股份有限公司 | A method of based on linux system reading-writing optical module register |
CN112988039B (en) * | 2019-12-18 | 2024-01-30 | 中国电信股份有限公司 | Data uploading method and device, cloud storage gateway and system and storage medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1424649A (en) * | 2003-01-09 | 2003-06-18 | 清华大学 | Robot controller with opening structure |
CN101216800A (en) * | 2008-01-02 | 2008-07-09 | 中兴通讯股份有限公司 | LINUX log controller and method |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20060085690A1 (en) * | 2004-10-15 | 2006-04-20 | Dell Products L.P. | Method to chain events in a system event log |
-
2010
- 2010-12-15 CN CN201010588992.6A patent/CN102455969B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1424649A (en) * | 2003-01-09 | 2003-06-18 | 清华大学 | Robot controller with opening structure |
CN101216800A (en) * | 2008-01-02 | 2008-07-09 | 中兴通讯股份有限公司 | LINUX log controller and method |
Non-Patent Citations (2)
Title |
---|
刘丹等.《系统安全中Linux日志的实用研究》.《世界电信》.2003,(第5期),44-46. * |
李亚洲.《基于串口通信的单片机日志系统设计》.《工业控制计算机》.2009,第22卷(第11期),44-45. * |
Also Published As
Publication number | Publication date |
---|---|
CN102455969A (en) | 2012-05-16 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11151010B2 (en) | Resource configuration method, mobile terminal and storage medium | |
CN102654858B (en) | Dual-processor system and communication method thereof | |
CN104461716B (en) | The access method and multi-core heterogeneous system of a kind of multi-core heterogeneous system | |
CN111459632B (en) | Serial port agent for calling terminal application program and implementation method | |
CN105141603B (en) | Communication data transmission method and system | |
CN108132868A (en) | A kind of data monitoring method, device, computing device and storage medium | |
CN102455969B (en) | Method for recording Linux serial communication log | |
CN103986585A (en) | Message preprocessing method and device | |
CN100476775C (en) | Host computer controller used for bus communication equipment and bus communication device | |
CN102223452A (en) | Method and system for testing text telephone (TTY) of mobile terminals | |
CN113259268A (en) | Network port and serial port data forwarding gateway and method supporting redundancy architecture | |
CN114710513A (en) | Network data processing system and method | |
CN102567081B (en) | Based on overall method to set up and the system of multi-process | |
CN103714060A (en) | Interrupt-period historical data processing method and front-end collecting sub system equipment | |
CN105472290A (en) | Processing method and device for data transmitting and receiving operation modes | |
CN107086960A (en) | A kind of message transmitting method and device | |
CN212364990U (en) | File storage system and intelligent device | |
CN101894082B (en) | Storage device and smartphone system | |
CN106816037A (en) | A kind of navigation channel traffic density and navigation channel Meteorological Index delivery system | |
CN105653477A (en) | Double-port RAM-based method for communication of hard core and soft core in FPGA | |
CN104243197A (en) | Data transmitting method and system and virtual storage gateways | |
CN103347086A (en) | Synergy kernel construction method based on distributed type negotiation algorithm | |
CN109542812A (en) | Data communication control method, device and terminal device | |
CN202334591U (en) | Multi-outlet connection system of network operator | |
CN220085381U (en) | Device for remote reading and writing of serial port equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |