A host and slave communication method and system

By introducing restart identification sync and expected identification hb in the host-slave communication, and setting the number threshold of slave data cache, the important response to data loss and configuration parameters is solved in the traditional communication method, and high-reliability communication is achieved.

CN115834723BActive Publication Date: 2025-04-22FUJIAN NEBULA ELECTRONICS CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202211442431.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-16
Publication Date
2025-04-22
Estimated Expiration
2042-11-16

AI Technical Summary

Technical Problem

The traditional master-slave mode communication method is prone to lose important response data in a strong interference environment, and the ordinary response and important response are combined to occupy a large amount of bus bandwidth at the same time, and it is impossible to know in real time whether the slave restarts, resulting in the configuration parameters being out of synchronization.

Method used

By adding restart identifier sync to normal commands and normal responses, adding the expected identifier hb to normal commands and important responses, and setting the number threshold of slave data caches, data interaction and configuration parameter synchronization are achieved.

Benefits of technology

Without significantly increasing the bus bandwidth load, communication reliability is improved, configuration parameters are synchronized during slave restart, and the probability of receiving important responses is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115834723B_ABST
    Figure CN115834723B_ABST
Patent Text Reader

Abstract

The present invention provides a host and slave communication method and system in the field of communication technology, the method comprising the following steps: step S10, configuring the formats of common commands, common responses and important responses, and setting the quantity threshold of slave data cache; step S20, the host and the slave perform initialization settings after starting operation, and synchronize configuration parameters based on the common commands and common responses; step S30, the host and the slave perform data exchange based on the common commands, important responses and quantity threshold. The advantage of the present invention is that the reliability of communication is greatly improved without significantly increasing the bus bandwidth load.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology, and in particular to a method and system for communication between a host and a slave. Background Art

[0002] In order to enhance the application value of devices, devices need to communicate for data exchange, and the communication between devices generally adopts the master-slave mode, that is, the devices are divided into host and slave, and the host and slave adopt a one-to-one communication mechanism. For example, the host sends a common command (such as a heartbeat command) to the slave, and the slave feeds back a common response to the host; when the slave needs to generate some events, the slave feeds back an important response to the host.

[0003] However, the traditional master-slave mode communication method has the following problems: 1. Ordinary responses and important responses are transmitted separately. When facing a strong interference environment, there is a probability that the relevant data of the important response will be lost; 2. If the ordinary response and the important response are combined into one, each feedback response must contain all the data of both, occupying more bus bandwidth; 3. The host cannot know whether the slave is restarted, resulting in the configuration parameters of the host and the slave being out of sync, and it is impossible to actively trigger the synchronization of the configuration parameters.

[0004] Therefore, how to provide a host and slave communication method and system to improve the reliability of communication without significantly increasing the bus bandwidth load has become a technical problem that needs to be solved urgently. Summary of the invention

[0005] The technical problem to be solved by the present invention is to provide a method and system for communication between a host and a slave, so as to improve the reliability of communication without significantly increasing the bus bandwidth load.

[0006] In a first aspect, the present invention provides a method for communication between a host and a slave, comprising the following steps:

[0007] Step S10, configuring the formats of common commands, common responses and important responses, and setting the quantity threshold of slave data cache;

[0008] Step S20: the host and the slave are initialized after starting and running, and synchronize configuration parameters based on the common commands and common responses;

[0009] Step S30: The host and the slave exchange data based on the common commands, important responses and quantity thresholds.

[0010] Furthermore, the step S10 is specifically as follows:

[0011] Configure common commands and common responses to carry the restart flag sync, configure common commands and important responses to carry the expectation flag hb, and set the number threshold x of slave data cache.

[0012] Furthermore, the restart flag sync is used to determine whether the slave is restarted, and its value is a positive integer greater than or equal to 0; the expectation flag hb is used to determine whether the data is synchronized and the data expected to be sent back, and its value is a positive integer greater than or equal to 0; when the value of the expectation flag hb is 0, it indicates a data synchronization command, and when the value is 1-n, it indicates that the corresponding number of data is expected to be sent back, and n is a positive integer.

[0013] Furthermore, the step S20 specifically includes:

[0014] Step S21: After the slave starts running, it automatically sets the restart flag sync carried in the common response to 0;

[0015] Step S22: After the host starts running, when it recognizes that the restart flag sync carried by the common response is 0, it synchronizes the configuration parameters of the slave;

[0016] Step S23, the host sets the restart flag sync carried by the common command to 1, and when the slave receives the common command sent by the host, it updates the restart flag sync carried by the common response based on the common command, and when the host sends the common command next time, it increments the restart flag sync carried by the common command, and so on;

[0017] Step S24: When the slave machine crashes and needs to be restarted, the restart flag sync carried in the normal response is automatically set to 0, and the process goes to step S22.

[0018] Furthermore, the step S30 specifically includes:

[0019] Step S31, the host sends a common command with the expected flag hb being 0 to the slave, the slave receives and parses the common command, and when the expected flag hb is obtained to be 0, it indicates that the host and the slave are performing data synchronization, the slave deletes the cached data, and sets the expected flag hb of the slave to 0;

[0020] Step S32, the host sends a common command with the expected identifier hb being m to the slave, and the slave updates the expected identifier hb of the important response based on the common command, and makes the important response carry the mth data, 1≤m≤n;

[0021] Step S33, the host receives and parses the important response to obtain the mth data, and determines whether it matches the set expected identifier hb. If so, m is incremented and the process proceeds to step S34; if not, the process proceeds to step S32;

[0022] Step S34, when the slave generates m+k data, it is determined whether k+1≤x is established. If so, the slave sends the data corresponding to the expected identifier hb set by the host to the host through an important response; if not, the slave sends the oldest data with cache to the host; wherein k is a positive integer;

[0023] Step S35, the host receives and parses the important response to obtain the data sent by the slave, and determines whether it matches the set expected identifier hb. If not, the value of the expected identifier hb is incremented and the process goes to step S34; if so, the process ends.

[0024] In a second aspect, the present invention provides a host and slave communication system, comprising the following modules:

[0025] Configuration module, used to configure the formats of common commands, common responses and important responses, and set the threshold of the number of slave data caches;

[0026] A configuration parameter synchronization module, used for initializing the host and the slave after startup, and synchronizing the configuration parameters based on the common commands and common responses;

[0027] The data interaction module is used for the host and the slave to perform data interaction based on the common commands, important responses and quantity thresholds.

[0028] Furthermore, the configuration module is specifically used for:

[0029] Configure common commands and common responses to carry the restart flag sync, configure common commands and important responses to carry the expectation flag hb, and set the number threshold x of slave data cache.

[0030] Furthermore, the restart flag sync is used to determine whether the slave is restarted, and its value is a positive integer greater than or equal to 0; the expectation flag hb is used to determine whether the data is synchronized and the data expected to be sent back, and its value is a positive integer greater than or equal to 0; when the value of the expectation flag hb is 0, it indicates a data synchronization command, and when the value is 1-n, it indicates that the corresponding number of data is expected to be sent back, and n is a positive integer.

[0031] Furthermore, the configuration parameter synchronization module specifically includes:

[0032] A slave startup unit, used for automatically setting the restart flag sync carried in the common response to 0 after the slave starts running;

[0033] A parameter synchronization unit, used for synchronizing the configuration parameters of the slave when the master recognizes that the restart mark sync carried in the common response is 0 after starting the operation;

[0034] A restart flag setting unit, used for the host to set the restart flag sync carried by the common command to 1, and when the slave receives the common command sent by the host, the slave updates the restart flag sync carried by the common response based on the common command, and when the host sends the common command next time, the restart flag sync carried by the common command is incremented, and so on;

[0035] The slave restart unit is used to automatically set the restart mark sync carried in the common response to 0 and enter the parameter synchronization unit when the slave crashes and needs to be restarted.

[0036] Furthermore, the data interaction module specifically includes:

[0037] A synchronous data deletion unit, used for the host to send a common command with the expected flag hb being 0 to the slave, and the slave receives and parses the common command. When the expected flag hb is 0, it indicates that the host and the slave are performing data synchronization, and the slave deletes the cached data and sets the expected flag hb of the slave to 0;

[0038] A data acquisition unit, used for the host to send a common command with the expected identifier hb being m to the slave, and the slave updates the expected identifier hb of the important response based on the common command, and makes the important response carry the mth data, 1≤m≤n;

[0039] The first data checking unit is used for the host to receive and parse the important response to obtain the mth data, and determine whether it matches the set expected identifier hb. If so, m is incremented and enters the cache data judgment unit; if not, it enters the data acquisition unit;

[0040] The cache data judgment unit is used to judge whether k+1≤x is established when the slave generates m+k data. If so, the slave sends the data corresponding to the expected identifier hb set by the host to the host through an important response; if not, the slave sends the oldest data with cache to the host; wherein k is a positive integer;

[0041] The second data verification unit is used for the host to receive and parse the important response to obtain the data sent by the slave, and determine whether it matches the set expected identifier hb. If not, the value of the expected identifier hb is incremented and enters the cache data judgment unit; if so, the process ends.

[0042] The advantages of the present invention are:

[0043] 1. By adding the restart flag sync to ordinary commands and ordinary responses, and adding the expectation flag hb to ordinary commands and important responses, that is, only one field is added to the downlink command and the uplink and downlink responses, the impact on the bus bandwidth load can be ignored; the restart flag sync can be used to quickly determine whether the slave has restarted, and the configuration parameters are automatically synchronized when the slave restarts to avoid the configuration parameters being out of sync; the expectation flag hb can be used to determine whether the important response sent by the slave matches the expected one, and if it does not match, the request is immediately re-issued, thereby greatly improving the probability of receiving the important response, and ultimately achieving a greatly improved communication reliability without significantly increasing the bus bandwidth load.

[0044] 2. By adding the restart flag sync to ordinary commands, ordinary commands are treated as heartbeats, so that data can be collected quickly even in low-priority situations.

[0045] 3. By setting the number threshold of slave data cache, that is, the number of data corresponding to the number threshold of the slave cache, and sending related data based on the cache order, the load of the bus bandwidth can be effectively reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The present invention will be further described below in conjunction with embodiments with reference to the accompanying drawings.

[0047] Figure 1 The present invention is a flow chart of a method for communicating between a host and a slave.

[0048] Figure 2 It is a structural schematic diagram of a host and slave communication system of the present invention. DETAILED DESCRIPTION

[0049] The technical solution in the embodiment of the present application has the following overall idea: adding a restart flag to ordinary commands and ordinary responses, and adding an expected flag to ordinary commands and important responses, that is, only one field is added to the downlink command and the uplink and downlink responses to reduce the load impact on the bus bandwidth; the restart flag is used to determine whether the slave automatically synchronizes the configuration parameters when it restarts, and the expected flag is used to determine whether the important response sent by the slave does not match the expected one, and then immediately re-requests to improve the reliability of communication.

[0050] Please refer to Figure 1 to Figure 2 As shown, a preferred embodiment of a host-slave communication method of the present invention comprises the following steps:

[0051] Step S10, configuring the formats of common commands, common responses and important responses, and setting the quantity threshold of slave data cache;

[0052] Step S20: the master and the slave are initialized after starting and running, and synchronize configuration parameters based on the restart identifier sync carried by the common command and the common response;

[0053] Step S30: The host and the slave exchange data based on the common commands, important responses and quantity thresholds.

[0054] The step S10 is specifically as follows:

[0055] Configure common commands and common responses to carry the restart flag sync, configure common commands and important responses to carry the expected flag hb, and set the number threshold x of slave data cache. The priority of the important response is higher than the common response, that is, the slave processes the important response first.

[0056] The restart flag sync is used to determine whether the slave is restarted, and its value is a positive integer greater than or equal to 0; the expectation flag hb is used to determine whether the data is synchronized and the data expected to be returned, and its value is a positive integer greater than or equal to 0; when the value of the expectation flag hb is 0, it indicates a data synchronization command, and when the value is 1-n, it indicates that the corresponding number of data is expected to be returned, and n is a positive integer; when the value of the expectation flag hb is not 0, the value increases from 1 to n, and then starts from 1 to cycle, to avoid overflow due to the upper limit of the data type.

[0057] The step S20 specifically includes:

[0058] Step S21: After the slave starts running, it automatically sets the restart flag sync carried in the common response to 0;

[0059] Step S22: After the host starts running, when it recognizes that the restart flag sync carried by the common response is 0, it synchronizes the configuration parameters of the slave;

[0060] Step S23, the host sets the restart flag sync carried by the common command to 1, and when the slave receives the common command sent by the host, it updates the restart flag sync carried by the common response based on the common command, and when the host sends the common command next time, it increments the restart flag sync carried by the common command by (++), and so on;

[0061] Step S24: When the slave machine crashes and needs to be restarted, the restart flag sync carried in the normal response is automatically set to 0, and the process goes to step S22.

[0062] The step S30 specifically includes:

[0063] Step S31, the host sends a common command with the expected flag hb being 0 to the slave, the slave receives and parses the common command, and when the expected flag hb is obtained to be 0, it indicates that the host and the slave are performing data synchronization, the slave deletes the cached data, and sets the expected flag hb of the slave to 0;

[0064] Step S32, the host sends a common command with the expected identifier hb being m to the slave, and the slave updates the expected identifier hb of the important response based on the common command, and makes the important response carry the mth data, 1≤m≤n;

[0065] Step S33, the host receives and parses the important response to obtain the mth data, and determines whether it matches the set expected identifier hb. If so, m is incremented and the process proceeds to step S34; if not, the process proceeds to step S32;

[0066] Step S34, when the slave generates m+k pieces of data, it is determined whether k+1≤x is established. If so, the slave sends the data corresponding to the expected identifier hb set by the host to the host through an important response; if not, the slave sends the oldest piece of data (the piece of data with the earliest cache time) with the cache to the host; wherein k is a positive integer;

[0067] Step S35, the host receives and parses the important response to obtain the data sent by the slave, and determines whether it matches the set expected identifier hb. If not, the value of the expected identifier hb is incremented and the process goes to step S34; if so, the process ends.

[0068] A preferred embodiment of a host-slave communication system of the present invention includes the following modules:

[0069] Configuration module, used to configure the formats of common commands, common responses and important responses, and set the threshold of the number of slave data caches;

[0070] A configuration parameter synchronization module is used for initializing the host and the slave after startup and synchronizing the configuration parameters based on the restart flag sync carried by the common command and the common response;

[0071] The data interaction module is used for the host and the slave to perform data interaction based on the common commands, important responses and quantity thresholds.

[0072] The configuration module is specifically used for:

[0073] Configure common commands and common responses to carry the restart flag sync, configure common commands and important responses to carry the expected flag hb, and set the number threshold x of slave data cache. The priority of the important response is higher than the common response, that is, the slave processes the important response first.

[0074] The restart flag sync is used to determine whether the slave is restarted, and its value is a positive integer greater than or equal to 0; the expectation flag hb is used to determine whether the data is synchronized and the data expected to be returned, and its value is a positive integer greater than or equal to 0; when the value of the expectation flag hb is 0, it indicates a data synchronization command, and when the value is 1-n, it indicates that the corresponding number of data is expected to be returned, and n is a positive integer; when the value of the expectation flag hb is not 0, the value increases from 1 to n, and then starts from 1 to cycle, to avoid overflow due to the upper limit of the data type.

[0075] The configuration parameter synchronization module specifically includes:

[0076] A slave startup unit, used for automatically setting the restart flag sync carried in the common response to 0 after the slave starts running;

[0077] A parameter synchronization unit, used for synchronizing the configuration parameters of the slave when the master recognizes that the restart mark sync carried in the common response is 0 after starting the operation;

[0078] A restart flag setting unit, configured for the host to set the restart flag sync carried by the common command to 1, and when the slave receives the common command sent by the host, to update the restart flag sync carried by the common response based on the common command, and when the host sends the common command next time, to increment (++) the restart flag sync carried by the common command, and so on;

[0079] The slave restart unit is used to automatically set the restart mark sync carried in the common response to 0 and enter the parameter synchronization unit when the slave crashes and needs to be restarted.

[0080] The data interaction module specifically includes:

[0081] A synchronous data deletion unit, used for the host to send a common command with the expected flag hb being 0 to the slave, and the slave receives and parses the common command. When the expected flag hb is 0, it indicates that the host and the slave are performing data synchronization, and the slave deletes the cached data and sets the expected flag hb of the slave to 0;

[0082] A data acquisition unit, used for the host to send a common command with the expected identifier hb being m to the slave, and the slave updates the expected identifier hb of the important response based on the common command, and makes the important response carry the mth data, 1≤m≤n;

[0083] The first data checking unit is used for the host to receive and parse the important response to obtain the mth data, and determine whether it matches the set expected identifier hb. If so, m is incremented and enters the cache data judgment unit; if not, enters the data acquisition unit;

[0084] The cache data judgment unit is used to judge whether k+1≤x is established when the slave generates m+k data. If so, the slave sends the data corresponding to the expected identifier hb set by the host to the host through an important response; if not, the slave sends the oldest data (the data with the earliest cache time) with cache to the host; wherein k is a positive integer;

[0085] The second data verification unit is used for the host to receive and parse the important response to obtain the data sent by the slave, and determine whether it matches the set expected identifier hb. If not, the value of the expected identifier hb is incremented and enters the cache data judgment unit; if so, the process ends.

[0086] In summary, the advantages of the present invention are:

[0087] 1. By adding the restart flag sync to ordinary commands and ordinary responses, and adding the expectation flag hb to ordinary commands and important responses, that is, only one field is added to the downlink command and the uplink and downlink responses, the impact on the bus bandwidth load can be ignored; the restart flag sync can be used to quickly determine whether the slave has restarted, and the configuration parameters are automatically synchronized when the slave restarts to avoid the configuration parameters being out of sync; the expectation flag hb can be used to determine whether the important response sent by the slave matches the expected one, and if it does not match, the request is immediately re-issued, thereby greatly improving the probability of receiving the important response, and ultimately achieving a greatly improved communication reliability without significantly increasing the bus bandwidth load.

[0088] 2. By adding the restart flag sync to ordinary commands, ordinary commands are treated as heartbeats, so that data can be collected quickly even in low-priority situations.

[0089] 3. By setting the number threshold of slave data cache, that is, the number of data corresponding to the number threshold of the slave cache, and sending related data based on the cache order, the load of the bus bandwidth can be effectively reduced.

[0090] Although the specific implementation modes of the present invention are described above, those skilled in the art should understand that the specific implementation modes described are only illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included in the scope of protection of the claims of the present invention.

Claims

1. A method for communication between a host and a slave, characterized in that: The steps include: Step S10, configure common commands and common responses to carry a restart flag sync, configure common commands and important responses to carry an expectation flag hb, and set a number threshold x for slave data cache; The restart flag sync is used to determine whether the slave is restarted, and its value is a positive integer greater than or equal to 0; the expectation flag hb is used to determine whether the data is synchronized and the data expected to be sent back, and its value is a positive integer greater than or equal to 0; when the value of the expectation flag hb is 0, it indicates a data synchronization command, and when the value is 1-n, it indicates that the corresponding number of data is expected to be sent back, and n is a positive integer; Step S20: the host and the slave are initialized after starting and running, and synchronize configuration parameters based on the common commands and common responses; Step S30: the host and the slave perform data exchange based on the common command, important response and quantity threshold; The step S20 specifically includes: Step S21: After the slave starts running, it automatically sets the restart flag sync carried in the common response to 0; Step S22: After the host starts running, when it recognizes that the restart flag sync carried by the common response is 0, it synchronizes the configuration parameters of the slave; Step S23, the host sets the restart flag sync carried by the common command to 1, and when the slave receives the common command sent by the host, it updates the restart flag sync carried by the common response based on the common command, and when the host sends the common command next time, it increments the restart flag sync carried by the common command, and so on; Step S24: When the slave machine crashes and needs to be restarted, the restart flag sync carried in the normal response is automatically set to 0, and the process goes to step S22.

2. A host-slave communication method as claimed in claim 1, characterized in that: The step S30 specifically includes: Step S31, the host sends a common command with the expected flag hb being 0 to the slave, the slave receives and parses the common command, and when the expected flag hb is obtained to be 0, it indicates that the host and the slave are performing data synchronization, the slave deletes the cached data, and sets the expected flag hb of the slave to 0; Step S32, the host sends a common command with the expected identifier hb being m to the slave, and the slave updates the expected identifier hb of the important response based on the common command, and makes the important response carry the mth data, 1≤m≤n; Step S33, the host receives and parses the important response to obtain the mth data, and determines whether it matches the set expected identifier hb. If so, m is incremented and the process proceeds to step S34; if not, the process proceeds to step S32; Step S34, when the slave generates m+k data, it is determined whether k+1≤x is established. If so, the slave sends the data corresponding to the expected identifier hb set by the host to the host through an important response; if not, the slave sends the oldest data with cache to the host; wherein k is a positive integer; Step S35, the host receives and parses the important response to obtain the data sent by the slave, and determines whether it matches the set expected identifier hb. If not, the value of the expected identifier hb is incremented and the process goes to step S34; if so, the process ends.

3. A host and slave communication system, characterized in that: Includes the following modules: Configuration module, used to configure common commands and common responses to carry the restart flag sync, configure common commands and important responses to carry the expectation flag hb, and set the number threshold x of slave data cache; The restart flag sync is used to determine whether the slave is restarted, and its value is a positive integer greater than or equal to 0; the expectation flag hb is used to determine whether the data is synchronized and the data expected to be sent back, and its value is a positive integer greater than or equal to 0; when the value of the expectation flag hb is 0, it indicates a data synchronization command, and when the value is 1-n, it indicates that the corresponding number of data is expected to be sent back, and n is a positive integer; A configuration parameter synchronization module, used for initializing the host and the slave after startup, and synchronizing the configuration parameters based on the common commands and common responses; A data interaction module, used for the host and the slave to perform data interaction based on the common commands, important responses and quantity thresholds; The configuration parameter synchronization module specifically includes: A slave startup unit, used for automatically setting the restart flag sync carried in the common response to 0 after the slave starts running; A parameter synchronization unit, used for synchronizing the configuration parameters of the slave when the master recognizes that the restart mark sync carried in the common response is 0 after starting the operation; A restart flag setting unit, configured for the host to set the restart flag sync carried by the common command to 1, and when the slave receives the common command sent by the host, to update the restart flag sync carried by the common response based on the common command, and when the host sends the common command next time, to increment the restart flag sync carried by the common command, and so on; The slave restart unit is used to automatically set the restart mark sync carried in the common response to 0 and enter the parameter synchronization unit when the slave crashes and needs to be restarted.

4. A host and slave communication system as claimed in claim 3, characterized in that: The data interaction module specifically includes: A synchronous data deletion unit, used for the host to send a common command with the expected flag hb being 0 to the slave, and the slave receives and parses the common command. When the expected flag hb is 0, it indicates that the host and the slave are performing data synchronization, and the slave deletes the cached data and sets the expected flag hb of the slave to 0; A data acquisition unit, used for the host to send a common command with the expected identifier hb being m to the slave, and the slave updates the expected identifier hb of the important response based on the common command, and makes the important response carry the mth data, 1≤m≤n; The first data checking unit is used for the host to receive and parse the important response to obtain the mth data, and determine whether it matches the set expected identifier hb. If so, m is incremented and enters the cache data judgment unit; if not, enters the data acquisition unit; The cache data judgment unit is used to judge whether k+1≤x is established when the slave generates m+k data. If so, the slave sends the data corresponding to the expected identifier hb set by the host to the host through an important response; if not, the slave sends the oldest data with cache to the host; wherein k is a positive integer; The second data verification unit is used for the host to receive and parse the important response to obtain the data sent by the slave, and determine whether it matches the set expected identifier hb. If not, the value of the expected identifier hb is incremented and enters the cache data judgment unit; if so, the process ends.

Citation Information

Patent Citations

  • Key data synchronizing method for multi-processor

    CN101562515A