CN101159760B - Method and system for implementing communication protocol based on XML data interchange file - Google Patents

Method and system for implementing communication protocol based on XML data interchange file Download PDF

Info

Publication number
CN101159760B
CN101159760B CN2007101820313A CN200710182031A CN101159760B CN 101159760 B CN101159760 B CN 101159760B CN 2007101820313 A CN2007101820313 A CN 2007101820313A CN 200710182031 A CN200710182031 A CN 200710182031A CN 101159760 B CN101159760 B CN 101159760B
Authority
CN
China
Prior art keywords
instruction
protocol
data
xml
command script
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.)
Expired - Fee Related
Application number
CN2007101820313A
Other languages
Chinese (zh)
Other versions
CN101159760A (en
Inventor
聂文强
邬向阳
吴晴
胡湘东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
ZTE Corp
Original Assignee
ZTE Corp
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by ZTE Corp filed Critical ZTE Corp
Priority to CN2007101820313A priority Critical patent/CN101159760B/en
Publication of CN101159760A publication Critical patent/CN101159760A/en
Application granted granted Critical
Publication of CN101159760B publication Critical patent/CN101159760B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention provides a method for achieving the communication protocol based on an XML data exchange file. The method comprises following steps: step S102, constructing an instruction script base represented in XML manner; step S104, receiving an instruction transmitted from a data application layer by an instruction resolver, searching the instruction script corresponding to the instruction in the instruction scrip base, packing the instruction, and transmitting the packed result to the communication interface; and step S106, de-packing the protocol data when the instruction resolver receives a protocol data fed back from the communication interface, and feeding the protocol data back to the data application layer. According to the invention, the flexibility of protocol resolving program is improved, which facilitates the protocol expansion and the rapid protocol achievement.

Description

Realize the method and system of communications protocol based on the XML data interchange file
Technical field
The present invention relates to the realization of communications protocol, relate in particular to based on extend markup language (extensible markup language is called for short XML) data interchange file and realize the method and system of communications protocol.
Background technology
At present, in network communication, often relate to the realization of communications protocol.Especially expand in the equipment requirements that communications protocol is also not really improved or increased newly under the situation such as communications protocol, realize that the program of agreement can be because above-mentioned former thereby become and become increasingly complex, perhaps the realization framework of original program all may be overthrown heavily.For example, the equipment that increases newly provides new function, and relevant communications protocol may reckon without in formulation process, therefore needs to expand communications protocol and comes to carry out communication with equipment.At this moment, expand communications protocol and revise its realization program, all can increase workload greatly, thereby incur loss through delay development progress.
For example, in a kind of wavelength-division product, webmaster and underlying device adopt makes agreement (S mouth communications protocol) communication by oneself, because newly-increased veneer or veneer add new function, the capital involves webmaster, upgrading is partly resolved in the instruction of the corresponding test program of veneer, brings bigger difficulty for exploitation, Version Control, test etc.
Summary of the invention
Technical problem to be solved by this invention is to realize communications protocol based on the XML data interchange file, makes the present invention according to this technical problem.
According to an aspect of the present invention, proposed a kind of method based on XML data interchange file realization communications protocol, this method may further comprise the steps: step S102, set up the command script storehouse that the XML mode is represented; Step S104, under the situation that receives the instruction that sends from data application layer, instruction parser is searched the command script of and instruction correspondence and is come instruction is packed in the command script storehouse, and the result that will pack sends to communication interface; And step S106, instruction parser unpacks protocol data receiving after the protocol data that communication interface returns, and it is returned to data application layer.
In addition, step S102 also comprises following processing: step S1022, and the communications protocol of analysis instruction extracts the general character of communications protocol; And step S1024, the general character of communications protocol is carried out abstract, and be described by the XML file.
Wherein, the general character of communications protocol comprises protocol massages head, protocol massages instruction and protocol massages parameter.
Realize the modification or the expansion in command script storehouse by the command script of revising or add in the described command script storehouse.
According to a further aspect in the invention, a kind of system that realizes communications protocol based on the XML data interchange file is provided, comprise data application layer and communication interface, this system also comprises: instruction parser, carry out alternately with data application layer and communication interface, be used for the instruction that the data application layer sends is resolved; And the command script storehouse represented of XML mode, be connected to instruction parser, be used to carry the command script that the XML mode is represented.
The command script that the XML data interchange file is write comprises the description of heading, the description of instruction and the description of parameter.Wherein, instruction comprises and class instruction is set and question and answer mode instructs; And parameter comprises the following parameter that sends instructions and the parameter of return data.
Instruction parser is under the situation that receives the instruction that sends from data application layer, searching the command script of and instruction correspondence in the command script storehouse that the ML of institute mode is represented comes instruction is packed, and the result that will pack sends to communication interface, and instruction parser unpacks protocol data receiving after the protocol data that communication interface returns, and it is returned to data application layer.
Adopt the method based on XML data interchange file realization communications protocol provided by the invention, can be easy to solve communications protocol family is not very big communications protocol problem of implementation.This method processing protocol is more flexible, especially is embodied in to expand and the modification agreement phase.The increase that the processing of program code also can not stop with the modification of communications protocol and expansion realizes difficulty.
Other features and advantages of the present invention will be set forth in the following description, and, partly from specification, become apparent, perhaps understand by implementing the present invention.Purpose of the present invention and other advantages can realize and obtain by specifically noted structure in the specification of being write, claims and accompanying drawing.
Description of drawings
Accompanying drawing is used to provide further understanding of the present invention, and constitutes the part of specification, is used from explanation the present invention with embodiments of the invention one, is not construed as limiting the invention.In the accompanying drawings:
Fig. 1 illustrates the flow chart of realizing the method for communications protocol based on the XML data interchange file according to of the present invention;
Fig. 2 is the flow chart that the concrete processing of step S102 among Fig. 1 is shown;
Fig. 3 illustrates the block diagram of realizing the system of communications protocol based on the XML data interchange file according to of the present invention; And
Fig. 4 illustrates the schematic diagram that the concrete processing of communications protocol is realized in command script storehouse that instruction parser among Fig. 3 and XML mode represent.
Embodiment
Below in conjunction with accompanying drawing the preferred embodiments of the present invention are described, should be appreciated that preferred embodiment described herein only is used for description and interpretation the present invention, and be not used in qualification the present invention.
Fig. 1 illustrates the flow chart of realizing the method for communications protocol based on the XML data interchange file according to of the present invention.
With reference to Fig. 1, this method may further comprise the steps: step S102, set up the command script storehouse that the XML mode is represented; Step S104, under the situation that receives the instruction that sends from data application layer, instruction parser is searched the command script of and instruction correspondence and is come instruction is packed in the command script storehouse, and the result that will pack sends to communication interface; And step S106, instruction parser unpacks protocol data receiving after the protocol data that communication interface returns, and it is returned to data application layer.
With reference to Fig. 2, step S102 also comprises following processing: step S1022, and the communication protocol of analysis instruction extracts the general character of communications protocol; And step S1024, the general character of communications protocol is carried out abstract, and be described by the XML file.
Wherein, the general character of communications protocol comprises protocol massages head, protocol massages instruction and protocol massages parameter.
Realize the modification or the expansion in command script storehouse by the command script of revising or add in the described command script storehouse.
Fig. 3 illustrates the block diagram of realizing the system of communications protocol based on the XML data interchange file according to of the present invention.
With reference to Fig. 3, according to the system based on XML data interchange file realization communications protocol of the present invention, comprise data application layer, communication interface, this system also comprises: instruction parser, carry out alternately with data application layer and communication interface, be used for the instruction that the data application layer sends is resolved; And the command script storehouse represented of XML mode, be connected to instruction parser, be used to carry the command script that the XML mode is represented.
Data application layer and communication interface are this type of communication program modular design methods that arrives commonly used.And, general just subsidiary packing and the parsing that has realized agreement of communication interface, this also is agreement change or expansion, a main cause that causes the modification of program difficulty to strengthen.In the present invention, protocol packing with resolve individual processing, and the command script of writing based on the XML data interchange file, it is simply clear to make between the program module, protocol extension reduces the program maintenance difficulty, even needn't update routine, and only add command script and get final product.
Fig. 4 illustrates the schematic diagram that the concrete processing of communications protocol is realized in command script storehouse that instruction parser among Fig. 3 and XML mode represent.
Instruction parser is under the situation that receives the instruction that sends from data application layer, searching the command script of and instruction correspondence in the command script storehouse that the ML of institute mode is represented comes instruction is packed, and the result that will pack sends to communication interface, and instruction parser unpacks protocol data receiving after the protocol data that communication interface returns, and it is returned to data application layer.
The command script that the XML data interchange file is write comprises the description of heading, the description of instruction and the description of parameter.Wherein, instruction comprises and class instruction is set and question and answer mode instructs; And parameter comprises the following parameter that sends instructions and the parameter of return data.
Instruction parser obtains heading, instruction, parameter respectively by the operation to the XML data file, then according to the synthetic message of the description of instruction.Simultaneously, receive the data that communication interface returns, according to the analysis mode of instruction description, data are resolved then.Give data application layer the result at last.
Be elaborated below in conjunction with a specific embodiment, so that purpose of the present invention, technical scheme and advantage are had more deep understanding.
At first, consider the message body of a simple communications protocol, as shown in the table:
Instruction comprises as giving an order:
1. channel frequence order (0x1000) is set
Parameter format:
Number of active lanes (2) | channel number (2), centre frequency (4) | channel number (2), centre frequency (4) | ...
Parameter declaration:
Channel number: the channel number number of carrying frequency, scope 1~40;
Centre frequency: with MHz is unit, rounds numerical value.
The instruction nothing is returned.
2. inquiry channel frequence order (0x2000)
Parameter format:
Number of active lanes (2) | channel number (2) | channel number (2) | ....
Parameter declaration:
Channel number: the channel number number of carrying frequency, scope 1~40.
Number of active lanes: value 0, all passages of expression inquiry, otherwise value 1~40.
Operation is returned:
Number of active lanes (2) | channel number (2), centre frequency (4) | channel number (2), centre frequency (4) | ...
Its concrete implementation step is described as follows:
At first, analyze communications protocol, extract the general character of communications protocol.This agreement is easy to distinguish parts such as heading, instruction, parameter.Heading is made up of 5 parts, is respectively: destination address, source address, command code, packets of information are grown, are kept, and have stipulated the word length of each several part.The parameter of instruction is along with the number of active lanes of inquiry or setting is inconsistent, and length is variable.
Then, the instruction of communications protocol heading, message, message parameter are carried out abstract, and can describe by the XML file.
At the present invention, heading can be described below:
<commhead>
<aim?len=”4”>1234</aim>
<source?len=”4”>4321</source>
<command>2</command>
<param>4</param>
<reserve>2</reserve>
</commhead>
Description herein can be very flexible, and field name can oneself define, but must be mapped one by one with the field of instruction parser the inside.Processing is Mr.'s cost script, does instruction parser again.
In the description of above-mentioned XML file,<aim len=" 4 " 1234</aim〉represent that the destination address of heading is 1234, take 4 bytes in the message the inside.If destination address is uncertain, then need to distinguish, for example can be filled into 1234 position with NULL, to pass to instruction parser to destination address in the place that application layer is called.The source field description source address situation.Command/param/reserve has described the word length of counterpart in the heading the inside respectively.
Message instruction can be synthesized with parameter and is described below:
<command code=" 0x1000 " name=" the channel frequence order is set "
<return>false</return>
<channel?num=”2”len=”2,4”>
<param>1,1961</param>
<param>10,1962</param>
</channel>
</command>
Mentioned order has been described the order 0x1000 that channel frequence is set, and has described code, command name, and the return item has been described order and do not returned, it is 2 that the channel item has been described port number, len represents first of parameter, and channel number accounts for 2 bytes in buffering area, and 4 expression frequencies account for 4 bytes.Param is concrete parameter.In addition, also need the unfixed situation of processing parameter, for example, the frequency of passage is set, may be relevant with user's selection, when application layer is called this instruction 0x1000 so, need import concrete parameter come in into, replace the fixed value of param the inside or revise the value of param the inside.
Describe from above-mentioned XML, field name can be more random, as long as be convenient to read, command description known get final product.
Next, write command process module, that is, and instruction parser.The whole process of writing instruction parser is exactly the processing XML file basically.For example, command process module is exposed to data application layer interface CallCommand (), 2 parameters of interface band, (char*pszCode, char*pszParam).Wherein pszCode illustrates the instruction of calling, and pszParam illustrates the param parameter of this instruction.If pszParam is empty, then represent to get parameter from XML script the inside.Then this interface can form the protocol data bag in the following manner:
1. protocol data buffering area → filling destination address buffering area → filling source address → filling pszCode → empty 4 bytes (parameter length) → empty 2 bytes are set to be kept.
2. if search the parameter of the corresponding pszCode of XML script file → read → read XML script file param item → call pszParam parameter is arranged, then fill; Otherwise fill the parameter that XML script file param item forms → parameter length is filled into the parameter length of step 1 → parameter is added to protocol data buffering area back → submissions communication interface transmission of step 1.
3. resolve the instruction of returning.Consider instruction 0x2000.
<command code=" 0x2000 " name=" order of inquiry channel frequence "
<return>true</return>
<channel?num=”3”len=”2”>
<param>1</param>
<param>10</param>
<param>13</param>
</channel>
<result>2,4</result>
</command>
Notice that the value of return has changed true into, represents can receive response after this instruction issues.If do not receive, that must be network or the other side's mistake.In addition, the result item has been stipulated the protocol package returned, remove heading after, the analysis mode of the parameter of back: 2 byte lanes number, 4 byte frequency values ....A plurality of values of one group [2 byte lanes, 4 byte frequencies] have so just been formed.Return to data application layer, thereby finish parsing.
At last, carry out agreement expansion or modification.The protocol resolver in the 3rd step can not be revised in suitable processing, only needs to revise or add to instruct the XML script file.For example, inquiry ambient temperature.Only needing the XML script file to add an instruction gets final product:
<command code=" 0x3000 " name=" the inquiry ambient temperature "
<return>true</return>
<channel?num=”1”len=”2”>
<param>1</param>
</channel>
<result>2</result>
</command>
Data application layer is when calling interface CallCommand, protocol resolver scanning XML scripting documents forms protocol package according to designated parameters, sends by communication interface, the data of returning by the analysis mode that should instruct is handled data, return to data application layer more then.
In the present embodiment, owing to adopted the mode of XML data interchange file to realize communications protocol, only need editor XML command script file, can realize packing and parsing rapidly to instruction, reduce the design difficulty and the maintenance difficulties of code greatly, under protocol suite is not very huge situation, tangible technical advantage is arranged.
Be the preferred embodiments of the present invention only below, be not limited to the present invention, for a person skilled in the art, the present invention can have various changes and variation.Within the spirit and principles in the present invention all, any modification of being done, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.

Claims (8)

1. the method based on XML data interchange file realization communications protocol is characterized in that, said method comprising the steps of:
Step S102 sets up the command script storehouse that the XML mode is represented;
Step S104, under the situation that receives the instruction that sends from data application layer, instruction parser is searched the command script corresponding with described instruction and is come described instruction is packed in described command script storehouse, and the result that will pack sends to communication interface; And
Step S106, described instruction parser unpack described protocol data receiving after the protocol data that described communication interface returns, and it is returned to described data application layer.
2. method according to claim 1 is characterized in that, described step S102 comprises following processing:
Step S1022 analyzes the communications protocol of described instruction, extracts the general character of described communications protocol; And
Step S1024 carries out abstractly to the general character of described communications protocol, and be described by the XML file.
3. according to the described method of claim 2, it is characterized in that the general character of described communications protocol comprises protocol massages head, protocol massages instruction and protocol massages parameter.
4. according to the described method of claim 1, it is characterized in that, realize the modification or the expansion in described command script storehouse by the command script of revising or add in the described command script storehouse.
5. the system based on XML data interchange file realization communications protocol comprises data application layer and communication interface, it is characterized in that described system also comprises:
Instruction parser, carry out alternately with data application layer and communication interface, be used for the instruction that the data application layer sends is resolved, wherein, described instruction parser is under the situation that receives the instruction that sends from data application layer, searching the command script corresponding with described instruction in the command script storehouse that the XML mode is represented comes described instruction is packed, and the result that will pack sends to communication interface, and described instruction parser unpacks described protocol data receiving after the protocol data that described communication interface returns, and it is returned to described data application layer; And
The command script storehouse that described XML mode is represented is connected to described instruction parser, is used to carry the command script that the XML mode is represented.
6. system according to claim 5 is characterized in that, the command script that described XML data interchange file is write comprises the description of heading, the description of instruction and the description of parameter.
7. system according to claim 6 is characterized in that, described instruction comprises and class instruction is set and question and answer mode instructs.
8. system according to claim 6 is characterized in that, the parameter that sends instructions under described parameter comprises and the parameter of return data.
CN2007101820313A 2007-10-24 2007-10-24 Method and system for implementing communication protocol based on XML data interchange file Expired - Fee Related CN101159760B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2007101820313A CN101159760B (en) 2007-10-24 2007-10-24 Method and system for implementing communication protocol based on XML data interchange file

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2007101820313A CN101159760B (en) 2007-10-24 2007-10-24 Method and system for implementing communication protocol based on XML data interchange file

Publications (2)

Publication Number Publication Date
CN101159760A CN101159760A (en) 2008-04-09
CN101159760B true CN101159760B (en) 2011-09-21

Family

ID=39307678

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2007101820313A Expired - Fee Related CN101159760B (en) 2007-10-24 2007-10-24 Method and system for implementing communication protocol based on XML data interchange file

Country Status (1)

Country Link
CN (1) CN101159760B (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101394312B (en) * 2008-11-12 2011-06-01 烽火通信科技股份有限公司 Method and system for managing and parsing XML format uni-disk protocol
CN101944025A (en) * 2010-09-16 2011-01-12 福建鑫诺通讯技术有限公司 Automatic TCP/UDP (Transmission Control Protocol/User Datagram Protocol) data packing and unpacking method based on PYTHON language
CN102739413A (en) * 2012-06-14 2012-10-17 国电南瑞科技股份有限公司 Communication protocol method of integrated supervisory control system (ISCS) and public address (PA) system of rail transit
CN103856453B (en) * 2012-11-30 2016-12-21 中国科学院沈阳自动化研究所 A kind of data transmission method towards semiconductor production line handling system
CN105139053B (en) * 2015-10-15 2018-01-30 江苏本能科技有限公司 Radio-frequency identification reader/writer interface protocol debugging apparatus and method
CN106951250B (en) * 2017-03-20 2020-09-22 苏州浪潮智能科技有限公司 Instruction analysis method and device based on option identification
CN108737123A (en) * 2017-04-13 2018-11-02 厦门科灿信息技术有限公司 A kind of configuration method of collector communications protocol
CN109818926B (en) * 2018-12-25 2020-10-09 西安长远电子工程有限责任公司 Communication method without preplanning
CN110225076A (en) * 2019-04-16 2019-09-10 深圳壹账通智能科技有限公司 File interaction method, apparatus, electronic equipment and storage medium
CN112612535A (en) * 2020-12-07 2021-04-06 河南方达空间信息技术有限公司 XML and JSON based satellite receiving system network communication coding and decoding engine method
CN113542216A (en) * 2021-06-04 2021-10-22 北京机电工程研究所 Automatic conversion method and device for interface protocol
CN114090523B (en) * 2022-01-19 2022-06-07 荣耀终端有限公司 Electronic device, and node parsing method and medium for XML file thereof

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1564489A (en) * 2004-04-19 2005-01-12 中兴通讯股份有限公司 Testing method for limitting status machine of communication system

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1564489A (en) * 2004-04-19 2005-01-12 中兴通讯股份有限公司 Testing method for limitting status machine of communication system

Also Published As

Publication number Publication date
CN101159760A (en) 2008-04-09

Similar Documents

Publication Publication Date Title
CN101159760B (en) Method and system for implementing communication protocol based on XML data interchange file
CN101695032B (en) Unified web client, service configuration method and system thereof
CN102739654B (en) Method for realizing application program to access database
US8549497B2 (en) High-level hypermedia synthesis for adaptive web
US20020087596A1 (en) Compact tree representation of markup languages
CN100433013C (en) Method and system for demonstrating data by tree-mode structure
CN101815093A (en) Method for adapting webpage to mobile terminal and mobile terminal page adaptation device
CN110489323A (en) Visual RPC API adjustment method, device, medium and equipment
CN110457144A (en) A kind of method, apparatus that realizing front end applications, medium and equipment
US20120047494A1 (en) Application programming interface (api) router implementation and method
CN107797823A (en) Business Rule Management method, apparatus, storage medium and computer equipment
CN107861723A (en) Mass data processing method and its system
CN107479873A (en) A kind of APP page modules melt forwarding method, electronic equipment and storage medium
CN103812946B (en) Method and system for online cloud updating of AR application program
CN105843663B (en) Decoding method suitable for the description of ASN.1 recursion resolution data structure
CN107040613A (en) A kind of message transmitting method and system
CN106933828B (en) Data insertion method and device
CN110134380A (en) A kind of code generating method based on template engine, device and electronic equipment
CN107800552A (en) A kind of data interactive method and device
CN104753891B (en) A kind of XML message analysis method and device
CN105786529B (en) One type Managed Code calls the Parameters design of the labyrinth of C/C++ style function
CN111736835A (en) Form processing method and device and storage medium
KR102407941B1 (en) User interface generation method of electronic device calling function or procedure of external device based on remote procedure call(rpc), program and electronic device thereof
CN110099033A (en) A kind of slave computer framework and the hardware Query method in real time in CANFD bus data library
CN103546527B (en) A kind of extendible industrial configuration or simulation software communication method

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
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20110921

Termination date: 20171024

CF01 Termination of patent right due to non-payment of annual fee