WO2019179384A1 - 一种通信方法及相关设备 - Google Patents
一种通信方法及相关设备 Download PDFInfo
- Publication number
- WO2019179384A1 WO2019179384A1 PCT/CN2019/078438 CN2019078438W WO2019179384A1 WO 2019179384 A1 WO2019179384 A1 WO 2019179384A1 CN 2019078438 W CN2019078438 W CN 2019078438W WO 2019179384 A1 WO2019179384 A1 WO 2019179384A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- request message
- sent
- application
- bus
- target
- Prior art date
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40143—Bus networks involving priority mechanisms
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/50—Queue scheduling
- H04L47/62—Queue scheduling characterised by scheduling criteria
- H04L47/625—Queue scheduling characterised by scheduling criteria for service slots or service orders
- H04L47/6275—Queue scheduling characterised by scheduling criteria for service slots or service orders based on priority
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L47/00—Traffic control in data switching networks
- H04L47/50—Queue scheduling
- H04L47/62—Queue scheduling characterised by scheduling criteria
- H04L47/6285—Provisions for avoiding starvation of low priority queues
Definitions
- the present application relates to the field of communications, and in particular, to a communication method and related devices.
- Multiple devices can be connected together via a bus to form a communication network and communicate in accordance with a certain bus communication protocol.
- the device that sends the request is usually called the master device, and the device that receives the request is called the slave device.
- a master device can be connected to multiple slave devices via a single bus.
- the master device may be an Internet of Things gateway, and the slave device may be an object terminal such as a smart refrigerator or a smart air conditioner.
- the master device initiates a communication request to the slave device over the bus and only allows one slave device to answer at the same time.
- an edge computing gateway when a master device is allowed to install multiple applications (applications, APPs), multiple applications need to use the bus to initiate a communication request to the slave device, in order to avoid communication conflicts, multiple The application preempts the right to use the bus.
- the application that obtains the right to use the bus monopolizes the bus and initiates a communication request to the slave device over the bus.
- the application time of the bus to the bus is determined by the application. If an application takes too long to occupy the bus, it will affect the communication timeliness of other applications, thereby causing the user experience. Poor.
- the present application provides a communication method and related equipment, which can avoid the problem that an application program installed in the main device takes too long on the bus, affects the communication timeliness of other applications, and improves the user experience.
- the first aspect of the present application provides a communication method, where the method is applied to a master device, and the method includes:
- the bus driver interface is called to send the first request message in the queue to be sent to the first target slave device; and then, the response time of the response message sent by the first target slave device to the first request message is obtained, and the If the response time meets the first preset condition, if the second request message exists in the queue to be sent, the bus driver interface is called to send the second request message to the second target slave device.
- the first request message is the first to be sent request message in the queue to be sent
- the second request message is the next request message in the queue to be sent adjacent to the first request message.
- the first preset condition is that the first request message and the response message sent by the first target slave device for the first request message are not allowed to continue to occupy the bus; or the first request message and The response message sent by the first target slave device for the first request message no longer needs to continue to occupy the bus.
- the request packets to be sent are sorted, and the sorted pending request packets are stored in the queue to be sent.
- the master device automatically releases the bus occupied by the first application, so as to install other applications in the main device.
- the program uses this bus. Therefore, it is avoided that an application installed in the master device takes too long time on the bus, thereby affecting the communication timeliness of other applications and improving the user experience.
- the first preset condition includes:
- the master device after receiving the first request message from the first target slave device, the master device does not receive the first response message from the first target slave device. Any response from a target device.
- the bus is always occupied by the first application, but no valid data appears on the bus. If the first application sets a long time occupation time for the bus, the bus is always waiting for the first target slave to send a response message when the occupied time of the bus set by the first application is not reached. status. In this case, first of all, other applications cannot use the bus to communicate with other slave devices, thus affecting the communication timeliness of other applications. Second, the bus is not actually used to transfer data for a period of time, resulting in a problem of low bus utilization.
- the master device automatically releases the bus occupied by the first application program, so that the master This bus is used by other applications installed in the device. Therefore, it is avoided that an application installed in the master device takes too long time on the bus, thereby affecting the communication timeliness of other applications and improving the user experience.
- the first preset condition includes:
- the timing is started from the time when the first request message is sent, and the end of the response message is obtained in the second preset time period.
- the sent response message is generally encapsulated in advance, and then the encapsulated response message is sent through the bus.
- the response message will contain an end flag, which is the end of the response message. If the first target slave device has sent the end of the frame through the bus, it indicates that the response message has been sent. In view of this, if the master device obtains the end of the response message, it indicates that the communication between the first application and the first target slave has been completed. At this point, the master automatically releases the bus occupied by the first application so that other applications installed in the host device use the bus. Therefore, it is avoided that an application installed in the master device takes too long time on the bus, thereby affecting the communication timeliness of other applications and improving the user experience.
- the first preset condition includes,
- the timing starts from the time when the data of one minimum transmission unit in the response message is acquired, and the data of the next minimum transmission unit is not received within the third preset time period.
- the bus is The processing of the response message of the first request message has been completed.
- the master automatically releases the bus occupied by the first application so that other applications installed in the host device use the bus. Therefore, it is avoided that an application installed in the master device takes too long time on the bus, thereby affecting the communication timeliness of other applications and improving the user experience.
- the first request message includes a priority of the first request message
- the method further includes:
- the priority of the to-be-sent request message is set according to the urgency and/or the degree of importance of the to-be-sent request message, so that the master device can send the packet according to the to-be-sent request message.
- the priority of the request packet determines the sorting position of the to-be-sent request message in the plurality of to-be-sent request messages, and further determines the storage location of the to-be-sent request message in the queue to be sent, so that the priority is to be sent. Messages can be processed first.
- the first request message further includes an identifier of the target application, where the first request message is determined to be in the to-be-sent queue according to the priority of the first request message.
- the priority of the first request packet is within the target priority range, determining, according to the priority of the first request packet, a storage location of the first request packet in the to-be-sent queue .
- the priority of the request packet to be sent is set to be high, so as to achieve the purpose that the packet to be sent is preferentially processed.
- the master device may verify the priority carried in the to-be-sent request message, and determine whether the priority is within a reasonable priority range. Inside. In this way, on the one hand, the message with high priority to be sent can be preferentially processed, and on the other hand, the application can be prevented from maliciously competing for the bus.
- the method further includes:
- the communication address set includes at least one communication address of a slave device that communicates with the target application
- one master device and multiple slave devices can be connected to one bus.
- the user When multiple applications are installed on the primary device, the user expects each application to communicate only with the authorized slave device over the bus.
- the application With the method provided in the embodiment of the present application, the application can be controlled to communicate only with its intended slave device, but not with other slave devices.
- the parsing the communication address of the first target slave device from the first request message includes:
- the communication address of the first target slave device is parsed from the first request packet.
- the target application when the target application communicates with the first target slave device, the first request packet sent needs to meet a certain packet sending rule. If the target application does not send the first request message to the first target slave device according to the specified message sending rule, even if the first request message is sent out through the bus, the first target slave device cannot correctly parse the first request message. Text, causing the target application and the first target slave device to fail to communicate. Therefore, in the present application, it is first determined whether the first request message satisfies the message sending rule of the target application, and the first request message is executed only if the first request message satisfies the message sending rule of the target application. The request message is parsed, sent through the bus, and the like. If not, the first request message is discarded, and the first request message can be prevented from occupying the bus to a certain extent.
- the method further includes:
- the application corresponding to the first request message is prohibited from using the bus to send the first request message again.
- the usage of the communication resources by each application program should be relatively uniform, and there are few applications that excessively occupy communication resources.
- the application may be a rogue application, and the rogue application should be prohibited from continuing to occupy communication resources.
- the master device can also monitor the usage of the communication resources, and when the rogue application is found, the rogue application is prohibited from continuing to occupy the communication resources, thereby preventing the rogue application from irrationally occupying the bus.
- the communication resource usage parameter includes at least one of the following:
- the data amount of the first request message, the data amount of the response message, the time taken after the first request message is sent, and the time to stop acquiring the response message, and the response is obtained from the beginning.
- the application that causes the communication resource to be abnormal may be prohibited from continuing to occupy the communication resource, thereby preventing the application from irrationally occupying the bus.
- the method further includes:
- the master device can record the abnormal condition, so as to perform maintenance and repair on the bus abnormal condition, by checking the record information, thereby determining the bus cause. The cause of the anomaly.
- the master device can also alarm to prompt the user to have an abnormality in the bus, so that the user can handle the bus abnormality in time.
- the master device may also accumulate the number of times the complete response message sent by the first target slave device for the first request message is not received, thereby determining the number of times the first application causes the bus abnormality.
- a second aspect of the present application provides a communication apparatus, which is applied to a master device, and specifically corresponds to the function of the communication method provided by the above first aspect.
- the functions may be implemented by hardware or by corresponding software implemented by hardware.
- the hardware or software includes one or more units corresponding to the functions described above, which may be software and/or hardware.
- the apparatus includes: a first request message sending unit and a response message acquiring unit; the first request message sending unit is configured to invoke a bus driving interface to be the first in the queue to be sent Requesting a message to be sent to the first target slave device;
- the response message obtaining unit is configured to acquire a response time of the response message sent by the first target slave device to the first request message, if the response time meets a first preset condition, and the And sending, by the bus driver interface, the second request packet to the second target slave device, where the second request packet is the to-be-sent queue and the first A request message that is adjacent to the request message.
- the first preset condition includes:
- the timing starts from the time when the data of one minimum transmission unit in the response message is acquired, and the data of the next minimum transmission unit is not received within the third preset time period.
- the first request message includes a priority of the first request message
- the device also includes:
- a storage location determining unit configured to determine, according to a priority of the first request packet, a storage location of the first request packet in the to-be-sent queue, before the first request packet is sent.
- the first request message further includes an identifier of the target application, where the storage location determining unit includes: a target priority range obtaining subunit and a storage location determining subunit;
- the target priority range is obtained by using a sub-unit, configured to obtain a target priority range of the target application according to the identifier of the target application and the correspondence between the application identifier and the priority range;
- Determining, by the sub-unit, the first request according to the priority of the first request message, when the priority of the first request message is within the target priority range The storage location of the message in the queue to be sent.
- the apparatus further includes: a communication address set obtaining unit, and a communication address parsing unit;
- the communication address set obtaining unit is configured to acquire a communication address set of the target application corresponding to the first request message, where the communication address set includes at least one communication address of a slave device that communicates with the target application;
- the communication address resolution unit is configured to parse the communication address of the first target slave device from the first request message
- the first request message sending unit is configured to send, when the communication address of the first target slave device exists in the communication address set, send the first request message in the queue to be sent through the bus The step of giving the first target a slave device.
- the communication address resolution unit is specifically configured to acquire a packet sending rule corresponding to the target application.
- the communication address of the first target slave device is parsed from the first request packet.
- the apparatus further includes: a resource usage information statistics unit and a prohibition of using the bus unit;
- the resource usage information statistics unit is configured to send, according to the fourth preset time period, the communication resource usage information corresponding to the first request message;
- the prohibiting the use of the bus unit when the communication resource usage information satisfies the unreasonable use condition, prohibiting the application corresponding to the first request message from using the bus to send the first request message again.
- the communication resource usage parameter includes at least one of the following:
- the data amount of the first request message, the data amount of the response message, the time taken after the first request message is sent, and the time to stop acquiring the response message, and the response is obtained from the beginning.
- the device further includes: a recording unit;
- the recording unit is configured to perform recording, alarming, and/or accumulating the number of times the complete response message is not received.
- a third aspect of the present application provides a communication device, where the device includes: a processor and a memory;
- the memory is configured to store an instruction
- the processor configured to execute the instructions in the memory, to perform the method of any of the above first aspects.
- a fourth aspect of the present application provides a computer readable storage medium comprising instructions which, when executed on a computer, cause the computer to perform the method of any of the above first aspects.
- a fifth aspect of the present application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of any of the above first aspects.
- FIG. 1 is a schematic diagram of an application scenario provided by an embodiment of the present application
- FIG. 2 is a schematic flowchart of a communication method according to an embodiment of the present application.
- FIG. 3 is a schematic flowchart of still another communication method according to an embodiment of the present application.
- FIG. 4 is a schematic flowchart of monitoring usage of a communication resource by a master device according to an embodiment of the present disclosure
- FIG. 5 is a schematic diagram of still another application scenario provided by an embodiment of the present application.
- FIG. 6 is a schematic diagram of signaling interaction of a communication method according to an embodiment of the present disclosure.
- FIG. 7 is a schematic structural diagram of a communication apparatus according to an embodiment of the present application.
- FIG. 8 is a schematic structural diagram of a communication device according to an embodiment of the present disclosure.
- the embodiment of the present invention provides a communication method and related device, which can prevent an application program installed in the main device from occupying the bus for too long, thereby affecting the communication timeliness of other applications and improving the user experience.
- FIG. 1 is a schematic diagram of an application scenario of an embodiment of the present application.
- the master device 100 and the slave device communicate via the RS-485 bus 300.
- the main device 100 is installed with a plurality of applications, namely, an application 110, an application 120, an application 130, and an application 140.
- the slave device includes a slave device 210, a slave device 220, a slave device 230, a slave device 240, and From device 250.
- the applications 110, 120, 130, and 140 can autonomously set their own occupation time for the RS-485 bus 300.
- the application 110 can communicate with the slave device 210 by using the RS-485 bus 300; the application 120 can communicate with the slave device 220 by using the RS-485 bus 300; the application 130 can communicate with the slave device 230 by using the RS-485 bus 300; The application 140 can communicate with the slave device 240 using the RS-485 bus 300, and can communicate with the slave device 250 using the RS-485 bus 300. It will be appreciated that when the application 110 communicates with the slave device 210 using the RS-485 bus 300, other applications are not allowed to communicate using the RS-485 bus 300.
- the application 110 is not allowed to take too long for the RS-485 bus 300, and if the application 110 sets a long pair of RS-485 bus for itself.
- the occupation time of 300 may affect other applications, such as the communication timeliness of the application 120, when the application 110 occupies the RS-485 bus 300 bus.
- the embodiment of the present application provides a communication method and related device, which can avoid the problem that an application program installed in the main device takes too long to occupy the bus, affects the timeliness of communication of other applications, and improves the problem. user experience.
- the bus in the embodiment of the present application includes, but is not limited to, a bus that is exclusive and does not have a collision detection mechanism such as an RS-485 bus or an M-BUS bus.
- FIG. 2 is a schematic flowchart diagram of a communication method according to an embodiment of the present application. The communication method provided in the embodiment of the present application is described in detail below.
- the communication method provided by the embodiment of the present application is applied to a master device, and the method may be implemented by using steps 201-202.
- Step 201 The bus driver interface is called to send the first request message in the queue to be sent to the first target slave device.
- Step 202 Acquire a response time of the first target slave device to send a response message to the first request message, determine whether the response time meets the first preset condition, and if yes, perform step 203.
- the master device may be an Internet of Things gateway. Multiple applications can be installed on the master device, and each application accesses the corresponding slave device through the bus.
- the embodiment of the present application does not specifically limit the slave device.
- the slave device may be a smart television, a smart refrigerator, a smart air conditioner, or the like.
- the embodiment of the present application does not specifically limit the bus drive interface, and the bus drive interface is related to the bus.
- the bus drive interface is an RS-485 bus drive interface.
- an application that communicates with the first target slave device is referred to as a first application.
- the first request message is a request message sent by the first application program to the first target slave device by the bus driver interface, that is, the first request message is from the first application,
- the intended recipient of a request message is the first target slave.
- the request message to be sent by the master device may be first reported.
- the text is sorted, and the sorted pending request message is stored in the queue to be sent.
- the first request message is a request message to be sent in the to-be-sent queue. After the bus processes the first request message, the next request message to be sent in the to-be-sent queue is sent.
- bus mentioned in the foregoing processing the first request message may include at least the following three situations:
- the response message from the first target slave device is not received within the first preset time period. That is to say, the timing is started from the time when the first request message is sent, and the response message from the first target slave device is not received within the first preset time period.
- the first preset time period in the embodiment of the present application is set in advance, and the specific value of the first preset time period is not limited in the embodiment of the present application, and the specific value of the preset time period may be based on the first
- the functions implemented by the application are determined or determined based on other conditions.
- the response packet from the first target slave device is not received in the first preset time period, that is, the master device sends the first request packet to the first target slave device. After that, no response is received from the first target slave device.
- the bus is always occupied by the first application, but no valid data appears on the bus. If the first application sets a long time occupation time for the bus, the bus is always waiting for the first target slave to send a response message when the occupied time of the bus set by the first application is not reached. status. In this case, first of all, other applications cannot use the bus to communicate with other slave devices, thus affecting the communication timeliness of other applications. Second, the bus is not actually used to transfer data for a period of time, resulting in a problem of low bus utilization.
- the master device if the response message is received from the time when the first request message is sent, and the response message from the first target slave device is not received within the first preset time period, the master device considers that The processing of the first request message has ended, and the next request message can be processed.
- the master device sets the occupation time of the bus for the first application, and the occupation time of the bus is not set by the application itself, so that the first target receives the slave device.
- the primary device sends the first request message, if no response is made, the bus occupied by the first application is released, and the other pending request message in the queue to be sent is processed by the bus, instead of keeping the bus at all times. Waiting to receive the status of the first target slave device sending a response message.
- the tail of the response message is obtained in the second preset time period.
- the sent response message is generally encapsulated in advance, and then the encapsulated response message is sent through the bus.
- the response message will contain an end flag, which is the end of the response message. If the first target slave device has sent the end of the frame through the bus, it indicates that the response message has been sent. In view of this, it is determined that the communication between the first application and the first target slave device is completed, and the received response message may be parsed to obtain the end of the response message, and if the frame end of the response message is obtained, Then the response message has been sent.
- the response message received by the bus includes the end of the response message, it indicates that the communication between the first application and the first target slave has been completed.
- the first application should release the bus it occupies so that other applications can use the bus to communicate with the corresponding slave device.
- the first application sets a long time for the bus itself, then even if the communication between the first application and the first target slave is completed, the first application does not actively release the bus. Therefore, other applications cannot utilize bus communication, which affects the communication timeliness of other applications.
- the bus sends the first request message to the first target slave device
- the frame tail of the response message sent by the first target slave device is acquired in the second preset time period. Then, the master device considers that the processing of the first request packet has ended, and can process the next request packet. That is, the time from the time when the first request message is sent is started. If the frame tail of the response message is obtained within the second preset time period, the master device considers that the processing of the first request message has ended. Can process the next request message. It should be noted that the reason for obtaining the end of the response message sent from the first target slave device in the second preset time period is to prevent the bus from being occupied by the first application for too long.
- the amount of data of the first request message is large, and the time for sending the first request message is long; or the amount of response message sent by the first target slave device is large, resulting in sending the response message.
- the time is too long. Therefore, the bus is always occupied by the first application, so that it is unable to process the pending request message of other applications.
- the master device controls the An application releases its occupied bus so that it can use the bus to process other pending request messages in the queue to be sent. This avoids the problem that the first application occupies the bus for a long time.
- the time from the time when the data of one minimum transmission unit in the response message is acquired is started, and the data of the next smallest transmission unit is not received within the third preset time period.
- the sent response message may be encapsulated in advance, and then the encapsulated response message is sent through the bus. Therefore, the encapsulated response message is contiguous when transmitted over the bus, and the time interval between data of two adjacent minimum transmission units transmitted on the bus in the encapsulated message should be relatively small. Correspondingly, the time interval between the data acquired by the master device and the two adjacent minimum transmission units should be relatively small. In other words, if the time interval between the data of the two adjacent minimum transmission units obtained by the master device is relatively large, it can be considered that the data of the two adjacent minimum transmission units received is not the data in the same response message.
- the bus is directed to the The processing of the response message of a request message has been completed.
- the first target slave device encapsulates the response packet, and the encapsulated response message includes 10 bytes.
- the first target slave device sends the 10 bytes of response message data through the bus, and the data of the minimum transmission unit of the response message is one byte of data. Therefore, when the 10 bytes of data are transmitted on the bus, The transmission interval between two adjacent byte data should be relatively small, and the time interval between the acquisition of two adjacent byte data by the master device is also small.
- the master device obtains two adjacent byte data at a relatively long interval, it can be considered that the two adjacent byte data acquired by the master device are not the data in the same response message. That is to say, if the time at which the one byte data in the response message is acquired from the master device starts counting, and the next byte data is not acquired in the third preset time period, the bus indicates the response message. Processing has been completed.
- the third preset time period in the embodiment of the present application is preset.
- the specific value of the third preset time period is not limited in the embodiment of the present application, and the specific value of the preset time period may be based on the bus.
- the baud rate is determined and can also be determined based on other conditions.
- the embodiment of the present application does not specifically limit the data of the minimum transmission unit.
- the data of the minimum transmission unit is described as the byte data in the above, this does not constitute a limitation on the embodiment of the present application.
- the data of the minimum transmission unit mentioned in the example may also be bit data, double byte data or the like.
- the first preset condition needs to be described. In the embodiment of the present application, determining whether the response time meets the first preset condition is to determine whether the bus has processed the first request message.
- the first preset condition is that the first request message and the response message sent by the first target slave device for the first request message are not allowed to continue to occupy the bus; or the first request message The response message sent by the device and the first target slave device for the first request message no longer needs to continue to occupy the bus.
- the response time mentioned in the embodiment of the present application refers to the time associated with the first target slave device sending a response message for the first request message.
- the response time in the embodiment of the present application includes: response message waiting time.
- the response message waiting time refers to the time when the first target slave device sends a response message to the master device. That is to say, the time from the time when the first request message is sent starts, and the time between the time when the first request message is sent and the time when the response message sent by the first target slave device is received is recorded.
- the response time meets the first preset condition, specifically: starting from the time when the first request message is sent, and if the response message is not received within the first preset time period, the response time satisfies the first Preset conditions. It can be understood that, when the response time is the response message waiting time, the response time meets the first preset condition, indicating that the primary device sends the first request message to the first target slave device after the first preset time period. No response was received from the first target slave device. At this point, it can be considered that the bus has processed the first request message, that is, the bus is not allowed to be occupied in order to process the first request message.
- the response time is the response message waiting time, and the response time meets the first preset condition
- the specific description of the part of the first request message that the bus has been processed may be referred to the “first type” in step 201. The description in the case is not repeated here.
- the response time in the embodiment of the present application includes: a frame tail acquisition time.
- the frame tail acquisition time mentioned in the embodiment of the present application refers to the time between the time when the first request message is sent and the time when the frame end time of the response message is obtained, that is, the first request message is sent. And the total time of receiving the response message sent by the first target slave device. Specifically, when the response time is the end of the frame, the response time meets the first preset condition, that is, the time is started from the time when the first request message is sent, and the response message is obtained in the second preset time period. The end of the frame. That is to say, after the end of the frame of the response message is obtained, there is no need to continue to occupy the bus for processing the first request message.
- the response time in the embodiment of the present application includes: a minimum transmission unit acquisition interval time.
- the minimum transmission unit acquisition interval time mentioned in the embodiment of the present application means that the time is started from the time when the data of one minimum transmission unit in the response message is acquired, until the data of the next smallest transmission unit is not received. time. Specifically, when the response time is the minimum transmission unit acquisition interval time, the response time satisfies the first preset condition, that is, starting from the time when the data of the minimum transmission unit in the response message is acquired, in the third preset The data of the next minimum transmission unit is not received within the time period.
- the response time is the minimum transmission unit acquisition interval time, and the response time satisfies the first preset condition
- the specific description of the part of the first request message that the bus has processed may be considered as reference to the above “third case”. The description in the section is not repeated here.
- step 203 is performed.
- Step 203 Determine whether there is a second request message in the queue to be sent; if there is a second request message in the queue to be sent, go to step 204; if there is no second request message in the queue to be sent, the process ends.
- Step 204 The bus driver interface is called to send a second request message to the second target slave device, where the second request message is the next request message in the queue to be sent adjacent to the first request message.
- bus drive interface mentioned in the step 204 is the same as the "bus drive interface” mentioned in the step 201.
- bus drive interface refers to the description of the "bus drive interface” in the step 201, and details are not described herein again.
- step 203 and 204 when the first request message has been processed by the bus, it indicates that the first application has released the bus it occupies, so that other applications can use the bus to perform with other slave devices. Communication. That is to say, when the second request message exists in the to-be-sent queue, the second request message can be sent to the second target slave device by using the bus.
- the second request message is a request message sent by the second application program to the second target slave device through the bus, that is, the second request message is from the second application, and the second request is The intended recipient of the message is the second target slave.
- the first application and the second application may be the same application, or may be different applications. This embodiment of the present application does not limit this.
- the first target slave device and the second target slave device may be the same slave device, or may be different slave devices, which is not limited in this embodiment of the present application.
- the master device sorts the request packets to be sent, and stores the sorted packets to be sent in the queue to be sent, so that the bus can process the first request packet according to the queue to be sent.
- the pending request message determines the next pending request message.
- the second request message is the next request message adjacent to the first request message in the queue to be sent. Therefore, after the bus processes the first request, the second request message is confirmed as the next pending message. Request a message.
- the communication method provided by the embodiment of the present application when the primary device sends the first request packet in the queue to be sent to the first target slave device through the bus, monitors the response packet sent by the first target slave device for the first request packet. Response time. If the response time meets the first preset condition, it is determined whether there is a second request message in the message sending sequence, and if yes, the second request message is sent to the second target slave device. That is, when the communication method provided by the embodiment of the present application is used, the primary device automatically uses the first application when the first preset condition of the main line needs to be occupied in order to process the first request message. The occupied bus is released so that other applications installed in the master device use the bus. Therefore, it is avoided that an application installed in the master device takes too long time on the bus, thereby affecting the communication timeliness of other applications and improving the user experience.
- the master device may sort the request packets to be sent, and The sorted pending request message is stored in the queue to be sent. After the bus processes the first request message in the queue to be sent, the next processed request message is determined according to the to-be-sent request message in the queue to be sent.
- the following describes the specific implementation method in which the master device sorts the to-be-sent request packets to be sent and stores the sorted packets to be sent in the queue to be sent.
- the request message to be sent may be sent to the master device, and the request message to be sent by the master device is sorted, and The sorted pending request message is stored in the queue to be sent.
- the multiple request messages are sorted according to the time sequence of the to-be-sent request messages sent by the application received by the master device.
- the earlier the slave device is.
- the master device 100 receives the request message 1 sent by the application 110 at 11:30, and the host device 100 receives the request message 2 sent by the application 120 at 11:31 of the day.
- the master device 100 receives the request message 3 sent by the application 110 at 11:32 on the same day.
- the three to-be-sent request messages are sorted according to the time sequence in which the master device 100 receives the three to-be-sent request messages, and the result of the sorting is request message 1, request message 2, and request message 3.
- the request message 1, the request message 2, and the request message 3 are stored in the queue to be sent. After the bus has processed the previous request message, the request message 1 is processed again, after the bus has processed the request message 1, the request message 2 is processed again, and after the bus has processed the request message 2, the request message 3 is processed.
- the application when the application sends the to-be-sent request message to the master device, the application may set the priority of the to-be-sent request message according to the urgency and/or importance degree of the to-be-sent request message. Therefore, the master device determines, according to the priority of the to-be-sent request message, the sorting position of the to-be-sent request message in the plurality of to-be-sent request messages, and further determines the storage of the to-be-sent request message in the to-be-sent queue. position.
- the priority of the to-be-sent request message is added to the to-be-sent request message, so that the master device obtains the priority of the request message. Therefore, the sorting position of the to-be-sent request message in the plurality of to-be-sent request messages is determined, and the storage location of the to-be-sent request message in the to-be-sent queue is determined.
- the master device may verify the priority carried in the to-be-sent request message, and determine whether the priority is a reasonable priority. Within the range. The priority is within a reasonable priority range, which means that the priority is within the priority range set by the host device for the application.
- the master device After setting the priority range for the application in the master device, the master device stores the correspondence between the application identifier and the priority range. Therefore, in order to facilitate the primary device to determine the priority range corresponding to the application according to the to-be-sent request message sent by the application, the application may send its own identifier to the to-be-sent when the application sends the to-be-sent request message to the master device.
- the request message that is, the to-be-sent request message sent by the application to the master device, carries the identifier of the application, so that the master device can identify the application identifier carried in the to-be-sent request message, and the A mapping of application IDs and priority ranges to determine the priority range of the application.
- the first application uses the bus to send the first request message to the first target slave device as an example for description.
- the master device sets a priority range for the first application, and saves a mapping relationship between the first application layer program identifier and the first application priority range.
- the first request message is added with the priority of the first request message and the identifier of the first application, that is, the first request message carries The priority of the first request message and the identity of the first application.
- the master device After receiving the first request packet, the master device obtains the identifier of the first application carried in the first request packet, and obtains the correspondence between the identifier of the first application and the priority range of the first application.
- the priority position of the first request message in the plurality of to-be-sent request messages may be determined according to the priority of the first request message carried in the first request message, thereby determining that the first request message is to be sent.
- the storage location in the queue may be determined according to the priority of the first request message carried in the first request message, thereby determining that the first request message is to be sent.
- the master device may set a priority within the reasonable priority range for the first request packet. Level, and determining, according to the priority set by the primary device for the first request packet, the sorting position of the first request packet in the plurality of to-be-sent request messages, thereby determining the storage of the first request packet in the to-be-sent queue position.
- the embodiment of the present application does not specifically limit the specific value of the priority that the primary device sets the first request packet within the reasonable priority range.
- the master device may set the priority range corresponding to the first application. The highest priority is used as the priority of the first request message.
- the sending request message may be sorted according to the time sequence in which the master device receives the to-be-sent request message, thereby determining that the packet is to be sent.
- the storage location of the to-be-sent request message in the queue to be sent may represent the sorting position of the to-be-sent request message in multiple to-be-sent request messages.
- the embodiment of the present application does not specifically limit the implementation manner of the queue to be sent, and may be, for example, a linked list structure.
- the following describes a method for sorting the request packets to be sent by the master device provided by the embodiment of the present application, and storing the sorted messages to be sent in the queue to be sent.
- the last pending request message in the queue to be sent is being sent to the corresponding slave device through the bus, that is, the current bus is in the occupied state.
- the master device 100 receives the request message 4 sent by the application 110 at 11:31, and the master device 100 receives the request message 5 sent by the application 120 at 11:32 on the same day, and the master device 100 at 11:32 on the same day.
- the request message 6 sent by the application 110 is received.
- the priority of the request message 4, the request message 5, and the request message 6 are within a reasonable priority range, and the priority of the request message 4 is 5, and the priority of the request message 5 is At level 6, the priority of request message 6 is level 5. The higher the priority value, the higher the priority.
- the master device When the master device receives the request message 4, because the request message 4 is the only one to be sent, the master device requests the message 4 to be the first bit in the to-be-sent request message; when the master device receives When requesting message 5, since the priority of the request message 5 is higher than the request message 4, the master device ranks the request message 5 in the first place in the to-be-sent request message, and queues the request message 4 Sending the second bit in the request message; when the master device receives the request message 6, since the priority of the request message 6 is lower than the request message 5, the request message 6 is queued after the request message 5, and because The priority of the request message 6 is the same as the priority of the request message 4, but the time when the master device receives the request message 4 is earlier than the time when the 6 request message is received.
- the master device queues the request message 6 after the request message 4, that is, the master device ranks the request message 5 in the first place in the to-be-sent request message, and the request message 4 is ranked in the first to be sent request message.
- the second bit will queue the request message 6 in the third place of the message to be sent. And determining, according to the order of the three to-be-sent request messages, the storage locations of the three to-be-sent request messages in the to-be-sent queue.
- the master device that sorts the first request packet and stores the sorted first request packet in the queue to be sent. Executed before step 201. That is, in the embodiment of the present application, when the first request message carries the priority of the first request message, in step 201, the master device sends the first to the first target slave device through the bus to the first target slave device. Step A and step B may also be included before requesting a message.
- Step A The master device acquires a target priority range of the target application corresponding to the first request message.
- Step B If the priority of the first request message is within the target priority range of the target application, the storage location of the first request message in the queue to be sent is determined according to the priority of the first request message.
- the master device may obtain the target application according to the identifier of the target application carried in the first request packet and the mapping relationship between the target application identifier and the priority range of the target application.
- the target priority range of the program may be obtained by the master device.
- the target application corresponding to the first request message refers to an application that sends the first request message to the master device, that is, the first application.
- the target application's target priority range is the priority range that the primary device sets for the target application. That is, the priority range of the first application.
- the identifier of the target application refers to the identifier of the first application, which can be used to uniquely identify the first application.
- the master device may re-confirm a priority within the target priority range for the first request message. Determining the sorting position of the first request packet in the plurality of to-be-sent request messages according to the priority of the re-confirmation of the first request packet by the master device, thereby determining the storage of the first request packet in the to-be-sent queue position.
- a predetermined target priority range in the first application may be set.
- the priority within, for example, 2 is the priority of reconfirming the first request message.
- the urgency of the text is used to sort the sending request messages, so that the to-be-sent request messages corresponding to the important applications can be preferentially processed, and/or the urgency-to-send request messages can be preferentially processed.
- one master device and multiple slave devices can be connected to one bus.
- the user expects each application to communicate only with the authorized slave device over the bus.
- application 110 intelligently communicates with slave device 210 using RS-485 bus 300, but not with other slave devices
- application 120 can only utilize RS-485 bus 300 and slave devices 220 communicates, but cannot communicate with other slave devices
- application 130 can communicate with slave device 230 using RS-485 bus 300, but cannot communicate with other slave devices
- application 140 intelligently utilizes RS-485 bus 300 and slave Device 240 communicates with and from device 250 and cannot communicate with slave device 210, slave device 220, and slave device 230.
- the master device when receiving the to-be-sent request message sent by the application, the master device may further verify whether the request message to be sent is sent by the slave device authorized by the application. If the to-be-sent request message is sent to the slave device authorized by the application, the to-be-sent request message is sent to the corresponding slave device through the bus. That is to say, in the embodiment of the present application, before step 201, step 301 to step 303 may also be included.
- Step 301 Acquire a communication address set of the target application corresponding to the first request message, where the communication address set includes at least one communication address of the slave device that communicates with the target application.
- the target application corresponding to the first request message mentioned in the embodiment of the present application refers to an application that sends a first request message to the master device, that is, the first application.
- the set of communication addresses of the target application refers to the set of communication addresses of the authorized slave devices of the target application. It can be understood that the authorized slave device of the target application can be one slave device or multiple slave devices. When the target application has one authorized slave device, the target application's communication address set includes the communication address of the authorized one slave device, and when the target application's authorized slave device is multiple, the target application The set of communication addresses includes the communication addresses of the authorized plurality of slave devices. For example, it can be understood in conjunction with FIG. 1.
- the communication address of the target application is included in the communication address set of the target application; if the target application is the application 140, the communication of the target application is performed.
- the address set of the slave device 240 and the communication address of the slave device 250 are included in the address set.
- the master device when installing the target application, may determine, according to configuration information of the target application, a communication address of the authorized slave device of the target application, and save the The mapping relationship between the target application's communication address set and the target application's identity.
- the master device may obtain the identifier of the target application carried in the first request packet, and obtain the first request according to the mapping relationship between the identifier of the target application and the communication address set of the target application. The set of communication addresses of the target application corresponding to the message.
- Step 302 Parse the communication address of the first target slave device from the first request message.
- Step 303 Determine whether the communication address of the first target slave device exists in the communication address set of the target application. If yes, execute step 201; if no, execute step 304 to discard the first request message.
- the first request message carries the communication address of the first target slave device, so that the first target slave device carries the number according to the first request packet.
- a target slave device confirms that the first request message is a request message sent to the first target slave device, thereby responding to the first request message.
- step 201 can be performed to send the first request message to the first target slave device through the bus. If the communication address of the first target slave device does not exist in the communication address set of the target application, it indicates that the first target slave device is not the authorized slave device of the target application, that is, the target application cannot and the first The target communicates with the device. At this time, the first request packet can be discarded.
- the target application when the target application communicates with the first target slave device, the first request packet sent needs to meet a certain packet sending rule. If the target application does not send the first request message to the first target slave device according to the specified message sending rule, even if the first request message is sent out through the bus, the first target slave device cannot correctly parse the first request message. Text, causing the target application and the first target slave device to fail to communicate.
- the packet sending rule of the target application may include: part or all of information such as a frame header, a frame tail, a frame length, an identifier of the target application, and a communication address of the first target slave device, And the specific framing method.
- the embodiment of the present application does not specifically limit the packet sending rule of the target application, and the specific packet sending rule may be determined according to the specific type of the target application.
- the master device may first obtain the packet sending rule corresponding to the target application, and determine whether the packet sending rule of the first request packet satisfies the packet sending rule corresponding to the target application, and if so, Then, the communication address of the first target slave device is parsed from the first request message.
- the manner in which the master device obtains the packet sending rule corresponding to the target application is similar to the manner in which the master device obtains the communication address set of the target application, that is, the master device saves the target application identifier and the target application correspondingly when the target application is installed.
- the master device After the first request packet is received, the master device obtains the target application identifier carried in the first request packet, and uses the target application identifier and the packet corresponding to the target application to send the packet.
- the mapping relationship between the rules obtains the packet sending rule corresponding to the target application.
- the master device may verify the request packet to be sent sent by the application, and only when the request packet to be sent is sent to the slave device authorized by the application, The to-be-sent request message is sent to the corresponding slave device. If the request message to be sent is not sent to the slave device authorized by the application, the to-be-sent request message is discarded, so that the other to-be-sent request message uses the bus to communicate with the corresponding slave device. Improve bus utilization and communication timeliness of other applications.
- the usage of the communication resources by each application program should be relatively uniform, and there are few applications that excessively occupy communication resources.
- the application may be a rogue application, and the rogue application should be prohibited from continuing to occupy communication resources.
- the master device can also monitor the usage of the communication resource, and when the rogue application is found, the rogue application is prohibited from continuing to occupy the communication resource.
- the specific method for monitoring the usage of the communication resources by the master device is described by taking an example of monitoring whether the application corresponding to the first request packet is a rogue application.
- the method can be implemented by steps 401 to 402.
- Step 401 The communication resource usage information corresponding to the first request message is sent in the fourth preset time period.
- the communication resource usage information mentioned in the embodiment of the present application refers to information used for transmitting communication resources in order to send the first request message.
- the communication resource usage information may be the data amount of the first request message, the data amount of the response message sent for the first request message, and the time from the first request message being sent to the stop of acquiring the response message. The time, the time taken from the start of acquiring the response message to the stop of acquiring the response message, and one or more of the number of times the first request message is sent.
- the data volume of the first request packet may be the total number of bytes of the first request packet; the data volume of the response packet may be the total number of bytes of the response packet; after the first request packet is sent, the acquisition is stopped.
- the time taken by the response message to indicate that the application corresponding to the first request message and the first target slave device perform an interaction may represent the application corresponding to the first request message and the first target.
- the time taken by the slave device to interact with the bus the time taken from the start of the acquisition of the response message to the stop of the acquisition of the response message, the time taken by the first target slave device to send the response message, which can be characterized as the first
- the fourth preset time period is not specifically limited in the embodiment of the present application, and the fourth preset time period may be specifically set according to actual conditions.
- the fourth preset time period occupies 1 hour, and the fourth preset time period may be 10:00 am to 11:00 am, 11:00 am to 12:00 am, and the like;
- the length of time occupied by the fourth preset time period is 1 hour, and the fourth preset time period is a time period from when the first request message is sent, until the accumulated time is 1 hour.
- the communication resource usage information corresponding to the first request message is sent in the fourth preset time period, the communication resource usage information may be deleted.
- Step 402 If the communication resource usage information corresponding to the first request message is sent to meet the unreasonable use condition in the fourth preset time period, the application corresponding to the first request message is prohibited from using the bus to send the first request report again. Text.
- the communication resource usage information corresponding to the first request message is sent to meet the unreasonable use condition, and the communication resource usage information may exceed the preset threshold.
- the communication resource usage information corresponding to the first request packet sent in the fourth preset time period satisfies the unreasonable use condition, and may be that the total data volume of the first request packet is greater than the first preset data volume threshold;
- the communication resource usage information corresponding to the first request packet is sent to meet the unreasonable use condition in the fourth preset time period, and the total data volume of the response message sent for the first request packet is greater than the second preset data.
- the communication resource usage information corresponding to the first request packet in the fourth preset time period satisfies the unreasonable use condition, and may be after the first request message is sent to stop acquiring the response message.
- the total time spent is greater than the first preset time threshold; for example, the communication resource usage information corresponding to the first request message is sent in the fourth preset time period to satisfy the unreasonable use condition, and the response report may be obtained from the beginning.
- the total time taken to stop acquiring the response message is greater than the second preset time threshold; for example, the first request message is sent in the fourth preset time period.
- the source resource usage information satisfies the unreasonable use condition, and may be that the number of times the first request message is sent is greater than a preset number of times threshold.
- the statistical method for the communication resource information corresponding to the sending of the other request message is the same as the statistical method for the communication resource information corresponding to the first request message; correspondingly, it is determined that the other request message is sent. Whether the application uses too much communication resources, and the method of determining whether the application corresponding to the first request message is excessively occupied by the communication resource; when the application corresponding to the other request message excessively occupies the communication resource
- the processing measure is the same as the processing when the application corresponding to the first request message is excessively occupied by the communication resource. I will not repeat them here.
- the master device can also monitor the usage of the communication resource, and when the rogue application is found, the rogue application is prohibited from continuing to occupy the communication resource.
- an abnormality may occur when an application installed on the master device communicates with a corresponding slave device.
- the bus has been unreasonably occupied due to a device failure.
- the master device can also perform corresponding processing measures for the abnormal situation.
- timing may be started from a time when the first request message is sent, and if a complete response message is not received within the second preset time period, recording, alarming, and/or Or the cumulative number of times that a complete response message has not been received.
- the timing is started from the time when the first request message is sent, the complete response message is not received within the second preset time period. It means that the bus is occupied by the first application for too long. There are several reasons why the bus is taken up by the first application for too long.
- the first reason is that the amount of data of the first request message sent by the first application is large, and the time for sending the response message is too long. Therefore, the bus is always occupied by the first application.
- the second reason is that the amount of response packets sent by the first target slave device is large, and the time for sending the response packet is too long. Therefore, the bus is always occupied by the first application.
- the third reason is that after the first request message is sent, the first target slave device does not respond immediately, and the response message sent by the first target slave device is not sent within the second preset time period.
- the master device may record the abnormal situation, for example, recording the corresponding situation of the abnormal situation.
- the cause of the bus abnormality is determined by viewing the recorded information.
- the master device can alarm to prompt the user to have an abnormality in the bus, so that the user can process the bus abnormality in time.
- the master device may accumulate the number of times that the first target slave device does not receive the complete response message sent by the first request message, thereby determining the number of times the first application causes the bus abnormality.
- the master device may prohibit the first application from communicating with the first target slave device using the bus, thereby preventing the first application from communicating using the bus to cause a bus abnormality.
- the master device may perform all of the above four implementation manners, and may also perform one or more implementation manners of the foregoing four implementation manners.
- the embodiment of the present application is not specifically limited.
- FIG. 5 is a schematic diagram of an application scenario provided by the embodiment of the present application.
- the master device 100 is an Internet of Things gateway, and the gateway communicates with a plurality of slave devices through the RS-485 bus 300, which are the slave device 260, the slave device 270, the slave device 280, and the slave device 290, respectively.
- a plurality of applications which are an application 511, an application 512, an application 521, and an application 522, are installed on the Internet of Things gateway 100.
- the IoT gateway 100 tends to install the application into the virtual machine and is isolated from the main system 530 of the IoT gateway, thereby preventing the main system 530 from malfunctioning due to a defect of the application.
- Container technology is a common technique for installing applications into virtual machines.
- the container technology refers to dividing a part of the resources in the Internet of Things gateway for installing an application.
- the divided resources can form a container, which can be understood by referring to FIG. 5.
- 510 in FIG. 5 is a container
- 520 is also a container.
- Container 510 and container 520 each have their own virtual file system and associated resource devices.
- two containers 510 and 520 are installed, and two applications are installed in the containers 510 and 520, respectively, in which an application 511 and an application 512 are installed, and an application is installed in the container 520. 521 and application 522. All four applications require access to the RS-485 communication interface.
- "RS-485 device driver" 513 in the container 510 and “RS-485 device driver” 523 in the container 520 are all mapped to the "virtual RS-485 device driver" 531 in the host system, that is, The RS-485 device driver is not actually implemented in the containers 510 and 520, but the implementation of the "virtual RS-485 device driver" 531 in the main system is cited, and therefore, the interface of the "RS-485 device driver" 513 in the container is used. The call is actually called the corresponding interface of the "virtual RS-485 device driver" 531 in the main system.
- the interaction method provided by the embodiment of the present application can be implemented by the “virtual RS-485 device driver” 531 described in FIG. 5.
- two to-be-sent request messages are stored in the to-be-sent queue, which are the first request message and the second request message, respectively.
- the first request message is stored before the second request message.
- the first request message is a request message sent by the application 511 to the first target slave device 260
- the second request message is a request message sent by the application program 521 to the second target slave device 290.
- the communication method provided by the embodiment of the present application will be described below with reference to the application scenario shown in FIG. 5 and FIG.
- Step 601 The virtual RS-485 device driver 531 determines the packet sending rule corresponding to the target application according to the identifier of the target application (ie, the application 511) carried in the first request packet, and determines that the first request packet satisfies The message is sent by the rule.
- Step 602 The virtual RS-485 device driver 531 parses the communication address of the first target slave device from the first request message, and determines the communication address of the target application according to the identifier of the target application carried in the first request message. The set determines that the communication address of the first target slave device 260 is present in the set of communication addresses of the first target application.
- Step 603 The virtual RS-485 device driver 531 calls the conventional RS-485 device driver 532 to transmit the first request message to the first target slave device 260 by using the RS-485 bus 300.
- Step 604 The first target slave device 260 parses the received first request message, and determines that the first request message is a request message sent to itself.
- Step 605 The first target slave device 260 sends a response message to the target application by using the RS-485 bus 300.
- Step 606 The virtual RS-485 device driver 531 starts counting from the time when the data of one of the minimum transmission units in the response message is acquired, and does not receive the data of the next minimum transmission unit within the third preset time period, and determines The response message is received.
- Step 607 The virtual RS-485 device driver 531 queries the second request message in the to-be-sent queue.
- Step 608 The virtual RS-485 device driver 531 calls the conventional RS-485 device driver 532 to transmit a second request message to the second target slave device 290 by using the RS-485 bus 300.
- the traditional RS-485 device driver 532 can implement the function of converting the to-be-sent request message into a data conforming to the RS-485 communication protocol and transmitting it through the RS-485 bus 300.
- a communication device 700 specifically corresponds to the function of the communication method provided above.
- the function of the communication device 700 can be implemented by hardware, or can be implemented by hardware to execute corresponding software.
- the hardware or software includes one or more units corresponding to the functions described above, which may be software and/or hardware.
- the apparatus 700 may include: a first request message sending unit 710 and a response message acquiring unit 720.
- the first request message sending unit 710 is configured to call the bus driver interface to send the first request message in the queue to be sent to the first target slave device;
- the response message obtaining unit 720 is configured to obtain a response time of the response message sent by the first target slave device to the first request message, and if the response time meets the first preset condition, and the second request message exists in the sending queue Then, the bus driver interface is called to send a second request message to the second target slave device, where the second request message is the next request message adjacent to the first request message in the to-be-sent queue.
- the first preset condition includes:
- the timing is started from the time when the first request message is sent, and the frame tail of the response message is obtained in the second preset time period;
- the time from the time when the data of one minimum transmission unit in the response message is acquired is started, and the data of the next smallest transmission unit is not received within the third preset time period.
- the first request message includes a priority of the first request message
- the device 700 also includes:
- the storage location determining unit is configured to determine, according to the priority of the first request packet, a storage location of the first request packet in the queue to be sent, before the first request packet is sent.
- the first request message further includes an identifier of the target application, and the storage location determining unit is specifically configured to:
- the target priority range of the target application is obtained;
- the storage location of the first request message in the to-be-sent queue is determined according to the priority of the first request message.
- the apparatus 700 further includes: a communication address set obtaining unit, and a communication address parsing unit;
- a communication address set obtaining unit configured to acquire a communication address set of the target application corresponding to the first request message, where the communication address set includes at least one communication address of the slave device that communicates with the target application;
- a communication address resolution unit configured to parse the communication address of the first target slave device from the first request message
- the first request message sending unit 710 is configured to: when the communication address of the first target slave device exists in the communication address set, perform sending, by the bus, the first request message in the queue to be sent to the first target slave device step.
- the communication address resolution unit includes: a message sending rule acquiring subunit and a communication address obtaining subunit;
- a packet sending rule obtaining sub-unit is configured to obtain a packet sending rule corresponding to the target application
- the message sending rule obtaining sub-unit is configured to parse the communication address of the first target slave device from the first request message when the first request message meets the message sending rule.
- the apparatus 700 further includes: a resource usage information statistics unit and a prohibition use bus unit;
- the resource usage information statistics unit is configured to collect the communication resource usage information corresponding to the first request message in the fourth preset time period;
- the use of the bus unit is prohibited, and when the communication resource usage information satisfies the unreasonable use condition, the application corresponding to the first request message is prohibited from transmitting the first request message by using the bus again.
- the communication resource usage parameter includes at least one of the following:
- the apparatus 700 further includes: a recording unit;
- a recording unit for recording, alarming, and/or accumulating the number of times a complete response message has not been received.
- the master device automatically releases the bus occupied by the first application program. , so that other applications installed in the primary device use the bus. Therefore, it is avoided that an application installed in the master device takes too long time on the bus, thereby affecting the communication timeliness of other applications and improving the user experience.
- the communication device 800 includes a processor 810, a communication interface 820, and a memory 830.
- the number of the processors 810 in the communication device 800 may be one or more, and one processor is taken as an example in FIG.
- the processor 810, the communication interface 820, and the memory 830 may be connected through a bus system or other manners, wherein the connection through the bus system 840 is taken as an example in FIG.
- the processor 810 can be a central processing unit (CPU), a network processor (NP), or a combination of a CPU and an NP.
- Processor 810 can also further include a hardware chip.
- the hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof.
- the PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general array logic (GAL), or any combination thereof.
- communication interface 820 can be a communication interface that supports the RS-485 communication protocol. Communication interface 820 can integrate the functionality of receiving and transmitting data messages.
- the memory 830 may include a volatile memory (English: volatile memory), such as a random-access memory (RAM); the memory 830 may also include a non-volatile memory, such as a fast A flash memory (English: flash memory), a hard disk drive (HDD) or a solid-state drive (SSD); the memory 410 may also include a combination of the above types of memories.
- volatile memory such as a random-access memory (RAM)
- non-volatile memory such as a fast A flash memory (English: flash memory), a hard disk drive (HDD) or a solid-state drive (SSD)
- the memory 410 may also include a combination of the above types of memories.
- the memory 830 is configured to store a queue to be sent, a first preset time, a second preset time, a third preset time, and the like.
- the memory 830 stores an operating system and programs, executable modules or data structures, or a subset thereof, or an extended set thereof, wherein the programs may include various operational instructions for implementing various operations.
- the operating system can include a variety of system programs for implementing various basic services and handling hardware-based tasks.
- the processor 810 can read the program in the memory 830 to implement the communication method provided by the embodiment of the present application.
- the bus system 840 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus.
- the bus system 840 can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, only one thick line is shown in Figure 8, but it does not mean that there is only one bus or one type of bus.
- the embodiment of the present application further provides a computer readable storage medium, including instructions, when executed on a computer, causing a computer to execute the communication method provided by the above method embodiment.
- the embodiment of the present application further provides a computer program product comprising instructions, which when executed on a computer, cause the computer to execute the communication method provided by the above method embodiment.
- the disclosed system, apparatus, and method may be implemented in other manners.
- the device embodiments described above are merely illustrative.
- the division of the unit is only a logical function division.
- there may be another division manner for example, multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not executed.
- the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interface, device or unit, and may be in an electrical, mechanical or other form.
- the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed to multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of the embodiment.
- each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
- the above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
- the integrated unit if implemented in the form of a software functional unit and sold or used as a standalone product, may be stored in a computer readable storage medium.
- a computer readable storage medium A number of instructions are included to cause a computer device (which may be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods described in various embodiments of the present application.
- the foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and the like. .
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Small-Scale Networks (AREA)
- Computer And Data Communications (AREA)
Abstract
本申请实施例公开了一种通信方法及相关设备,该方法包括:调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备;获取第一目标从设备针对第一请求报文发送的应答报文的应答时间,若应答时间满足第一预设条件,且发送队列中存在第二请求报文,则调用总线驱动接口向第二目标从设备发送第二请求报文,第二请求报文为待发送队列中与第一请求报文相邻的后一个请求报文。由此可见,当满足不再允许或不再需要为了处理第一请求报文而需要占用主线的第一预设条件时,主设备自动将第一应用程序占用的总线释放,从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
Description
本申请涉及通信领域,尤其涉及一种通信方法及相关设备。
多个设备可以通过总线(bus)连接在一起形成通信网络,并按照一定的总线通信协议进行通信。通常将发送请求的设备称为主设备,接收请求的设备称为从设备。通过一条总线,一个主设备可以与多个从设备连接在一起。例如主设备可以是物联网关,从设备可以是诸如智能冰箱、智能空调等物联终端。主设备通过总线向从设备发起通信请求,并在同一时刻仅允许一个从设备应答。
在实际应用,例如,在边缘计算网关中,当主设备被允许安装多个应用程序(application,APP)时,多个应用程序均需要利用总线向从设备发起通信请求,为了避免通信冲突,多个应用程序会抢占对总线的使用权,获取到总线使用权的应用程序独占该总线,并通过总线向从设备发起通信请求。
然而,在以往的技术中,应用程序对总线的占用时间由应用程序来决定,若某个应用程序对总线的占用时间过长,则会影响到其他应用程序的通信及时性,进而导致用户体验较差。
发明内容
本申请提供了一种通信方法及相关设备,能够避免主设备中安装的某个应用程序对总线的占用时间过长,影响其它应用程序的通信及时性的问题,提高用户体验。
本申请第一方面提供一种通信方法,其中,该方法应用于主设备,所述方法包括:
首先,调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备;然后,获取第一目标从设备针对第一请求报文发送的应答报文的应答时间,判断该应答时间是否满足第一预设条件,在满足第一预设条件的前提下,若待发送队列中存在第二请求报文,则调用总线驱动接口向第二目标从设备发送第二请求报文。其中,第一请求报文为待发送队列中排序第一的待发送请求报文,第二请求报文为待发送队列中与第一请求报文相邻的后一请求报文。第一预设条件是指,第一请求报文和第一目标从设备针对该第一请求报文发送的应答报文不被允许继续占用总线时对应的条件;或,第一请求报文和第一目标从设备针对该第一请求报文发送的应答报文不再需要继续占用总线时对应的条件。
由此可见,在本申请提供的通信方法中,若主设备中安装有多个应用程序,则将待发送的请求报文进行排序,将排序后的待发送请求报文存储在待发送队列中,当满足不再允许或不再需要为了处理第一请求报文而需要占用主线的第一预设条件时,主设备自动将第一应用程序占用的总线释放,以便主设备中安装的其它应用程序使用该总线。从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
在一些可能的实现中,所述第一预设条件,包括:
从所述第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到所述应答报 文;
需要说明的是,在第一预设时间段内未接收到来自第一目标从设备的应答报文,是指,主设备向第一目标从设备发送第一请求报文之后,未收到第一目标从设备的任何响应。换言之,主设备向第一目标从设备发送第一请求报文之后,总线一直被第一应用程序占用,但是,总线上并未出现任何有效数据。若第一应用程序为自身设置了一个很长的对总线的占用时间,那么,在第一应用程序设置的对总线的占用时间未达到时,总线一直处于等待第一目标从设备发送应答报文的状态。对于这种情况,首先,其它应用程序不能利用总线与其它从设备进行通信,从而影响了其它应用程序的通信及时性。其次,总线在一段时间内实际上并未用于传输数据,从而造成了总线利用率低的问题。
因此,当从所述第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到所述应答报文时,主设备自动将第一应用程序占用的总线释放,以便主设备中安装的其它应用程序使用该总线。从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
在一些可能的实现中,所述第一预设条件,包括:
从所述第一请求报文发送的时刻开始计时,在第二预设时间段内获取到所述应答报文的帧尾。
需要说明的是,第一目标从设备发送应答报文时,一般会预先将发送的应答报文封装好,然后通过总线发送该封装好的应答报文。一般来讲,应答报文中会包含一个结束标志,即应答报文的帧尾。若第一目标从设备已经通过总线将帧尾发送出去,则表示该应答报文已经发送完毕。鉴于此,若主设备获取到应答报文的帧尾,则说明第一应用程序和第一目标从设备之间的通信已经完成。此时,主设备自动将第一应用程序占用的总线释放,以便主设备中安装的其它应用程序使用该总线。从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
在一些可能的实现中,所述第一预设条件,包括,
从获取到所述应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个所述最小传输单位的数据。
需要说明的是,若从主设备获取到应答报文中其中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未获取到下一个最小传输单位的数据,则说明总线针对第一请求报文的应答报文的处理已经完成。此时,主设备自动将第一应用程序占用的总线释放,以便主设备中安装的其它应用程序使用该总线。从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
在一些可能的实现中,所述第一请求报文中包括所述第一请求报文的优先级;
在所述第一请求报文被发送之前,所述方法还包括:
根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
需要说明的是,考虑到实际应用中,一方面,主设备上安装的各个应用程序的重要程度不同,另一方面,各个待发送请求报文的紧急程度不同。因此应用程序在向主设备发送待发送请求报文时,可以根据该待发送请求报文的紧急程度和/或重要程度设置该待发 送请求报文的优先级,以便于主设备根据该待发送请求报文的优先级确定该待发送请求报文在多个待发送请求报文中的排序位置,进而确定该待发送请求报文在待发送队列中的存储位置,使得优先级高的待发送报文能够被优先处理。
在一些可能的实现中,所述第一请求报文中还包括目标应用程序的标识,所述根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置包括:
根据所述目标应用程序的标识,以及应用程序标识与优先级范围之间的对应关系,得到所述目标应用程序的目标优先级范围;
若所述第一请求报文的优先级在所述目标优先级范围内,则根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
需要说明的是,在实际应用中,可能存在应用程序恶意竞争总线,将待发送的请求报文的优先级设置的很高,以达到其发送的待发送请求报文被优先处理的目的。鉴于此,在本申请中,主设备接收到应用程序发送的待发送请求报文之后,可以对该待发送请求报文中携带的优先级进行验证,判断该优先级是否在合理的优先级范围内。这样一来,一方面可以使得优先级高的待发送报文被优先处理,另一方面,还可以避免应用程序恶意竞争总线。
在一些可能的实现中,所述方法还包括:
获取所述第一请求报文对应的目标应用程序的通信地址集合,所述通信地址集合包括至少一个与所述目标应用程序通信的从设备的通信地址;
从所述第一请求报文中解析得到所述第一目标从设备的通信地址;
若所述第一目标从设备的通信地址存在于所述通信地址集合中,则执行所述通过总线将待发送队列中的第一请求报文发送给第一目标从设备的步骤。
需要说明的是,一条总线上可以连接一个主设备和多个从设备。当主设备上安装有多个应用程序时,用户期望各个应用程序只能通过总线和被授权的从设备通信。采用本申请实施例提供的方法,可以控制应用程序只与其既定的从设备进行通信,而不能与其它从设备进行通信。
在一些可能的实现中,所述从所述第一请求报文中解析得到所述第一目标从设备的通信地址包括:
获取所述目标应用程序对应的报文发送规则;
若所述第一请求报文符合所述报文发送规则,则从所述第一请求报文中解析得到所述第一目标从设备的通信地址。
需要说明的是,在实际应用中,目标应用程序与第一目标从设备进行通信时,发送的第一请求报文需要符合一定的报文发送规则。如果目标应用程序未按照规定的报文发送规则向第一目标从设备发送第一请求报文,即使第一请求报文通过总线发送出去,第一目标从设备也不能正确解析该第一请求报文,从而导致目标应用程序和第一目标从设备通信失败。因此,在本申请中,首先判断第一请求报文是否满足目标应用程序的报文发送规则,在第一请求报文是否满足目标应用程序的报文发送规则的前提下,才执行对第一请求报文进行解析、通过总线发送等动作,若不满足,则丢弃该第一请求报文,在一定程度上可以避免该第一请求报文占用总线。
在一些可能的实现中,所述方法还包括:
统计在第四预设时间段内发送所述第一请求报文对应的通信资源使用信息;
若所述通信资源使用信息满足不合理使用条件,则禁止与所述第一请求报文对应的应用程序利用所述总线再次发送所述第一请求报文。
需要说明的是,在实际应用中,当主设备安装有多个应用程序时,一般来讲,各个应用程序对通信资源的使用情况应该比较均匀,很少出现一些应用程序过多的占用通信资源的情况,若一些应用程序过多的占用通信资源,则该应用程序可能是流氓应用程序,应该禁止该流氓应用程序继续占用通信资源。鉴于此,在本申请中,主设备还可以监控通信资源的使用情况,当发现流氓应用程序时,禁止该流氓应用程序继续占用通信资源,避免流氓应用程序不合理占用总线。
在一些可能的实现中,所述通信资源使用参数至少包括以下任意一种:
所述第一请求报文的数据量、所述应答报文的数据量、从所述第一请求报文被发送之后到停止获取所述应答报文所花费的时间、从开始获取所述应答报文到停止获取所述应答报文所花费的时间,以及所述第一请求报文被发送的次数。
当主设备监控到上述通信资源的使用情况异常时,可以禁止导致该通信资源使用异常的应用程序继续占用通信资源,避免该应用程序不合理占用总线。
在一些可能的实现中,若在第二预设时间段内未接收到完整的所述应答报文,则所述方法还包括:
进行记录、报警和/或累计未接收到完整的应答报文的次数。
需要说明的是,若从第一请求报文发送的时刻开始计时,在第二预设时间段内未接收到完整的应答报文。则说明,总线被第一应用程序占用的时间过长。因此,在本申请中,对于这种总线被不合理占用的异常情况,主设备可以对该异常情况进行记录,以便于对总线异常情况进行维护修复时,通过查看该记录信息,从而确定引起总线异常的原因。主设备也可以报警,以提示用户总线出现异常,以便于用户及时对总线异常情况进行处理。主设备还可以累计未接收到第一目标从设备针对第一请求报文发送的完整的应答报文的次数,从而确定第一应用程序导致总线异常的次数。
本申请第二方面提供了一种通信装置,所述装置应用于主设备,具体对应于上述第一方面提供的通信方法的功能。所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括一个或多个与上述功能相对应的单元,所述单元可以是软件和/或硬件。
在一些可能的实现中,所述装置包括:第一请求报文发送单元和应答报文获取单元;所述第一请求报文发送单元,用于调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备;
所述应答报文获取单元,用于获取所述第一目标从设备针对所述第一请求报文发送的应答报文的应答时间,若所述应答时间满足第一预设条件,且所述发送队列中存在第二请求报文,则调用所述总线驱动接口向第二目标从设备发送所述第二请求报文,所述第二请求报文为所述待发送队列中与所述第一请求报文相邻的后一个请求报文。
在一些可能的实现中,所述第一预设条件,包括:
从所述第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到所述应答报文;
或者,
从所述第一请求报文发送的时刻开始计时,在第二预设时间段内获取到所述应答报文的帧尾;
或者,
从获取到所述应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个所述最小传输单位的数据。
在一些可能的实现中,所述第一请求报文中包括所述第一请求报文的优先级;
所述装置还包括:
存储位置确定单元,用于在所述第一请求报文被发送之前,根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
在一些可能的实现中,所述第一请求报文中还包括目标应用程序的标识,所述存储位置确定单元包括:目标优先级范围得到子单元和存储位置确定子单元;
所述目标优先级范围得到子单元,用于根据所述目标应用程序的标识,以及应用程序标识与优先级范围之间的对应关系,得到所述目标应用程序的目标优先级范围;
所述目标优先级范围得到子单元,用于当所述第一请求报文的优先级在所述目标优先级范围内时,根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
在一些可能的实现中,所述装置还包括:通信地址集合获取单元,通信地址解析单元;
所述通信地址集合获取单元,用于获取所述第一请求报文对应的目标应用程序的通信地址集合,所述通信地址集合包括至少一个与所述目标应用程序通信的从设备的通信地址;
所述通信地址解析单元,用于从所述第一请求报文中解析得到所述第一目标从设备的通信地址;
所述第一请求报文发送单元,用于当所述第一目标从设备的通信地址存在于所述通信地址集合中时,执行所述通过总线将待发送队列中的第一请求报文发送给第一目标从设备的步骤。
在一些可能的实现中,所述通信地址解析单元,具体用于获取所述目标应用程序对应的报文发送规则;
当所述第一请求报文符合所述报文发送规则时,从所述第一请求报文中解析得到所述第一目标从设备的通信地址。
在一些可能的实现中,所述装置还包括:资源使用信息统计单元和禁止使用总线单元;
所述资源使用信息统计单元,用于统计在第四预设时间段内发送所述第一请求报文对应的通信资源使用信息;
所述禁止使用总线单元,用于当所述通信资源使用信息满足不合理使用条件时,禁止与所述第一请求报文对应的应用程序利用所述总线再次发送所述第一请求报文。
在一些可能的实现中,所述通信资源使用参数至少包括以下任意一种:
所述第一请求报文的数据量、所述应答报文的数据量、从所述第一请求报文被发送之后到停止获取所述应答报文所花费的时间、从开始获取所述应答报文到停止获取所述应答报文所花费的时间,以及所述第一请求报文被发送的次数。
在一些可能的实现中,若在第二预设时间段内未接收到完整的所述应答报文,则所述装置还包括:记录单元;
所述记录单元,用于进行记录、报警和/或累计未接收到完整的应答报文的次数。
本申请第三方面提供了一种通信设备,所述设备包括:处理器和存储器;
所述存储器,用于存储指令;
所述处理器,用于执行所述存储器中的所述指令,执行以上第一方面任意一项所述的方法。
本申请第四方面提供了一种计算机可读存储介质,包括指令,当其在计算机上运行时,使得计算机执行以上第一方面任意一项所述的方法。
本申请第五方面提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行以上第一方面任意一项所述的方法。
图1为本申请实施例提供的一个应用场景示意图;
图2为本申请实施例提供的一种通信方法的流程示意图;
图3为本申请实施例提供的又一种通信方法的流程示意图;
图4为本申请实施例提供的主设备监控通信资源的使用情况的流程示意图;
图5为本申请实施例提供的又一个应用场景示意图;
图6为本申请实施例提供的一种通信方法的信令交互示意图;
图7为本申请实施例提供的一种通信装置的结构示意图;
图8为本申请实施例提供的一种通信设备的结构示意图。
本申请实施例提供了一种通信方法及相关设备,能够避免主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
本发明的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的实施例能够以除了在这里图示或描述的内容以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
在实际应用中,当主设备被允许安装多个应用程序时,多个应用程序均需要利用总 线向从设备发起通信请求,为了避免通信冲突,多个应用程序抢占对总线的使用权,获取到总线使用权的应用程序独占该总线,并通过总线向从设备发起通信请求,在同一时刻仅允许一个从设备应答。为了不影响主设备中安装的各个应用程序的通信及时性,一般不允许若某个应用程序对总线的占用时间过长。但是,现有的一些总线,例如,推荐标准(recommended standard,RS)RS-485总线、仪表总线(Meter BUS,M-BUS)等总线,当主设备和从设备通过这些总线进行通信时,并不能解决上述某个应用程序对总线的占用时间过长,影响主设备中安装的其他应用程序的通信及时性的问题。
例如,可结合图1进行理解,图1示出了本申请实施例的一个应用场景示意图。在图1所示的应用场景中,主设备100和从设备通过RS-485总线300进行通信。其中,主设备100中安装有多个应用程序,分别为应用程序110、应用程序120、应用程序130和应用程序140;从设备包括从设备210、从设备220、从设备230、从设备240和从设备250。应用程序110、120、130和140可以自主设置其自身对RS-485总线300的占用时间。其中,应用程序110可以利用RS-485总线300和从设备210通信;应用程序120可以利用RS-485总线300和从设备220通信;应用程序130可以利用RS-485总线300和从设备230通信;应用程序140既可以利用RS-485总线300和从设备240通信,又可以利用RS-485总线300和从设备250通信。可以理解的是,当应用程序110利用RS-485总线300和从设备210通信时,不允许其它应用程序利用该RS-485总线300通信。为了不影响主设备中安装的其它应用程序的通信及时性,不允许应用程序110对RS-485总线300的占用时间过长,而若应用程序110为自己设置了较长的对RS-485总线300的占用时间,则在应用程序110占用RS-485总线300总线时,可能会影响其它应用程序,例如应用程序120的通信及时性。
为了解决上述问题,本申请实施例提供一种通信方法及相关设备,能够避免主设备中安装的某个应用程序对总线的占用时间过长,影响其它应用程序的通信及时性的问题,改善了用户体验。本申请实施例中的总线包括但不限于RS-485总线、M-BUS总线等独占式且不具备冲突检测机制的总线。
参见图2,该图为本申请实施例提供的一种通信方法的流程示意图。以下对本申请实施例中提供的通信方法进行详细介绍。
本申请实施例提供的通信方法,应用于主设备,该方法可以通过步骤201-202实现。
步骤201:调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备。
步骤202:获取第一目标从设备针对第一请求报文发送应答报文的应答时间,判断该应答时间是否满足第一预设条件,如果是,执行步骤203。
如前文所述,在本申请实施例中,主设备可以为物联网关。主设备上可以安装多个应用程序,各个应用程序通过总线访问对应的从设备。本申请实施例不具体限定该从设备,例如,从设备可以为智能电视机、智能冰箱、智能空调等设备。
本申请实施例对总线驱动接口不做具体限定,总线驱动接口与总线相关。例如,当总线为RS-485总线时,总线驱动接口为RS-485总线驱动接口。
为方便描述,将与第一目标从设备通信的应用程序称为第一应用程序。
在本申请实施例中,第一请求报文为第一应用程序调用总线驱动接口发送给第一目标从设备的请求报文,也就是说,第一请求报文来自于第一应用程序,第一请求报文的既定接收方为第一目标从设备。
需要说明的是,在本申请实施例中,若主设备中安装有多个应用程序,当应用程序需要利用总线向对应的从设备发送请求报文时,可以先由主设备对待发送的请求报文进行排序,并将排序后的待发送请求报文存储在待发送队列中。
所述第一请求报文为所述待发送队列中当前待发送的请求报文,当总线处理完第一请求报文之后,发送所述待发送队列中下一条待发送的请求报文。
需要说明的是,前文提及的总线处理完第一请求报文,至少可以包括以下三种情况:
第一种情况:总线向第一目标从设备发送第一请求报文之后,在第一预设时间段内未接收到来自第一目标从设备的应答报文。也就是说,从第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到来自第一目标从设备的应答报文。
本申请实施例中的第一预设时间段为预先设置的,本申请实施例对该第一预设时间段的具体取值不做限定,该预设时间段的具体取值可以根据第一应用程序所实现的功能进行确定,也可以根据其它条件确定。
需要说明的是,本申请实施例中,在第一预设时间段内未接收到来自第一目标从设备的应答报文,是指,主设备向第一目标从设备发送第一请求报文之后,未收到第一目标从设备的任何响应。换言之,主设备向第一目标从设备发送第一请求报文之后,总线一直被第一应用程序占用,但是,总线上并未出现任何有效数据。若第一应用程序为自身设置了一个很长的对总线的占用时间,那么,在第一应用程序设置的对总线的占用时间未达到时,总线一直处于等待第一目标从设备发送应答报文的状态。对于这种情况,首先,其它应用程序不能利用总线与其它从设备进行通信,从而影响了其它应用程序的通信及时性。其次,总线在一段时间内实际上并未用于传输数据,从而造成了总线利用率低的问题。
因此,在本申请实施例中,若从第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到来自第一目标从设备的应答报文,则主设备就认为对第一请求报文的处理已经结束,可以处理下一条请求报文。
也就是说,在本申请实施例中,由主设备为第一应用程序设置对总线的占用时间,而并不是由应用程序自身设置对总线的占用时间,从而使得在第一目标从设备接收到主设备发送第一请求报文之后,未做出任何响应的情况下,释放第一应用程序占用的总线,利用该总线处理待发送队列中的其它待发送请求报文,而不是使总线一直处于等待接收第一目标从设备发送应答报文的状态。
第二种情况,总线向第一目标从设备发送第一请求报文之后,在第二预设时间段内获取到应答报文的帧尾。
可以理解的是,第一目标从设备发送应答报文时,一般会预先将发送的应答报文封装好,然后通过总线发送该封装好的应答报文。一般来讲,应答报文中会包含一个结束标志,即应答报文的帧尾。若第一目标从设备已经通过总线将帧尾发送出去,则表示该 应答报文已经发送完毕。鉴于此,判断第一应用程序和第一目标从设备之间的通信已经完成,可以对接收到的应答报文进行解析,获取应答报文的帧尾,若获取到应答报文的帧尾,则说明应答报文已经发送完毕。换言之,若总线获取到的应答报文中包含应答报文的帧尾,则说明第一应用程序和第一目标从设备之间的通信已经完成。此时,第一应用程序应该将其占用的总线释放,以便其他应用程序利用该总线和对应的从设备通信。
若第一应用程序为自身设置了一个很长的对总线的占用时间,那么,即使第一应用程序和第一目标从设备之间的通信已经完成,第一应用程序也不会主动释放该总线,从而导致其它应用程序不能利用总线通信,进而影响了其它应用程序的通信及时性。
因此,在本申请实施例中,若总线向第一目标从设备发送第一请求报文之后,在第二预设时间段内获取到了来自第一目标从设备发送的应答报文的帧尾。则主设备就认为对第一请求报文的处理已经结束,可以处理下一条请求报文。也就是说,从第一请求报文发送的时刻开始计时,若在第二预设时间段内获取到应答报文的帧尾,则主设备就认为对第一请求报文的处理已经结束,可以处理下一条请求报文。需要说明的是,之所以限定在第二预设时间段内获取到来自第一目标从设备发送的应答报文的帧尾,是为了避免总线被第一应用程序占用的时间过长。从而影响其它应用程序的通信及时性。例如,第一请求报文的数据量很大,导致发送该第一请求报文的时间很长;或者,第一目标从设备发送的应答报文数据量很大,导致发送该应答报文的时间过长。故而,总线一直被第一应用程序占用,从而无法处理其它应用程序的待发送请求报文。
也就是说,在本申请实施例中,主设备向第一目标从设备发送第一请求报文,并获取到了来自第一目标从设备发送的应答报文的帧尾之后,主设备即控制第一应用程序释放其占用的总线,从而可以利用该总线处理待发送队列中的其它待发送请求报文。避免了第一应用程序长时间占用总线的问题。
第三种情况,从获取到应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个最小传输单位的数据。
可以理解的是,如前文所述,第一目标从设备发送应答报文时,可以预先将发送的应答报文封装好,然后通过总线发送该封装好的应答报文。因此,该封装好的应答报文在总线上传输时是连续的,该封装好的报文中在总线上传输的两个相邻最小传输单位的数据之间的时间间隔应该比较小。相应的,主设备获取到两个相邻最小传输单位的数据之间的时间间隔应该比较小。换言之,若主设备获取到两个相邻最小传输单位的数据之间的时间间隔比较大,则可以认为接收到的两个相邻最小传输单位的数据并非是同一条应答报文中的数据。也就是说,若从主设备获取到应答报文中其中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未获取到下一个最小传输单位的数据,则说明总线针对第一请求报文的应答报文的处理已经完成。例如,第一目标从设备将应答报文进行封装,封装后的应答报文包括10字节。第一目标从设备将这10个字节的应答报文数据通过总线发送出去,应答报文的最小传输单位的数据为一字节数据,因此,这10个字节数据在总线上传输时,两个相邻字节数据之间的发送时间间隔应该比较小,主设备获取到两个相邻字节数据之间的时间间隔也比较小。若主设备获取到两个相邻字节数据的时间间隔比较大,可以认为主设备获取到的两个相邻字节数据并非是同一条应答报文 中的数据。也就是说,若从主设备获取到应答报文中其中一个字节数据的时刻开始计时,在第三预设时间段内未获取到下一字节数据,则说明总线对该应答报文的处理已经完成。
本申请实施例中的第三预设时间段为预先设置的,本申请实施例对该第三预设时间段的具体取值不做限定,该预设时间段的具体取值可以根据总线的波特率确定,也可以根据其它条件确定。
需要说明的是,本申请实施例不具体限定最小传输单位的数据,虽然上文中以最小传输单位的数据为字节数据来进行说明,但这并不构成对本申请实施例的限定,本申请实施例中提及的最小传输单位的数据还可以为比特数据,也可以为双字节数据等。
第一预设条件需要说明的是,本申请实施例中,判断应答时间是否满足第一预设条件,是为了判断总线是否处理完了第一请求报文。其中,第一预设条件是指,第一请求报文和第一目标从设备针对该第一请求报文发送的应答报文不被允许继续占用总线时对应的条件;或,第一请求报文和第一目标从设备针对该第一请求报文发送的应答报文不再需要继续占用总线时对应的条件。
本申请实施例中提及的应答时间,是指,与第一目标从设备针对第一请求报文发送应答报文相关的时间。
在一种可能的实现方式中,本申请实施例中的应答时间,包括:应答报文等待时间。
应答报文等待时间,是指,等待第一目标从设备向主设备发送应答报文的时间。也就是说,从第一请求报文发送的时刻开始计时,记录从第一请求报文发送的时刻到接收到第一目标从设备发送的应答报文的时刻之间的时间。相应的,应答时间满足第一预设条件,具体为:从第一请求报文发送的时刻开始计时,若在第一预设时间段内未接收到应答报文,则该应答时间满足第一预设条件。可以理解的是,当应答时间为应答报文等待时间时,该应答时间满足第一预设条件,表示主设备向第一目标从设备发送第一请求报文之后,在第一预设时间段内未收到第一目标从设备的任何响应。此时,可以认为总线已经处理完了第一请求报文,即不允许为了处理第一请求报文再占用总线。
需要说明的是,关于应答时间为应答报文等待时间,且应答时间满足第一预设条件时,以认为总线已经处理完了第一请求报文部分的具体描述可以参考步骤201中“第一种情况”中的描述部分,在此不再赘述。
在另一种可能的实现方式中,本申请实施例中的应答时间,包括:帧尾获取时间。
本申请实施例中提及的帧尾获取时间,是指,从第一请求报文发送的时刻开始计时,到获取到应答报文的帧尾时刻之间的时间,即发送第一请求报文和接收第一目标从设备发送的应答报文的总时间。具体地,当应答时间为帧尾获取时间时,应答时间满足第一预设条件,是指,从第一请求报文发送的时刻开始计时,在第二预设时间段内获取到应答报文的帧尾。也就是说,当获取到应答报文的帧尾之后,就不需要为处理第一请求报文继续占用总线了。
需要说明的是,判断是否获取到了来自第一目标从设备发送的应答报文的帧尾的描述可以参考参考以上“第二种情况”中的描述部分,在此不再赘述。
需要说明的是,关于应答时间为帧尾获取时间,且应答时间满足第一预设条件时,可以认为总线已经处理完了第一请求报文部分的具体描述可以参考以上“第二种情况”中的描述部分,在此不再赘述。
在又一种可能的实现方式中,本申请实施例中的应答时间,包括:最小传输单位获取间隔时间。
本申请实施例中提及的最小传输单位获取间隔时间,是指,从获取到应答报文中一个最小传输单位的数据的时刻开始计时,直到未接收到下一个最小传输单位的数据之间的时间。具体地,当应答时间为最小传输单位获取间隔时间时,应答时间满足第一预设条件,是指,从获取到应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个所述最小传输单位的数据。
需要说明的是,关于应答时间为最小传输单位获取间隔时间,且应答时间满足第一预设条件时,可以认为总线已经处理完了第一请求报文部分的具体描述可以参考以上“第三种情况”中的描述部分,在此不再赘述。
步骤202中判断应答时间满足第一预设条件之后,执行步骤203。
步骤203:判断待发送队列中是否存在第二请求报文;如果待发送队列中存在第二请求报文,执行步骤204;若待发送队列中不存在第二请求报文,则结束流程。
步骤204:调用总线驱动接口向第二目标从设备发送第二请求报文,其中,第二请求报文为待发送队列中与第一请求报文相邻的后一个请求报文。
步骤204中提及的“总线驱动接口”与步骤201中提及的“总线驱动接口”相同,具体描述可以参考步骤201中关于“总线驱动接口”的描述,在此不再赘述。
关于步骤203和204,需要说明的是,当总线已经处理完了第一请求报文时,表示第一应用程序已经将其占用的总线释放,从而其它应用程序可以利用该总线与其它的从设备进行通信。也就是说,当待发送队列中存在第二请求报文时,即可利用总线向第二目标从设备发送第二请求报文。
在本申请实施例中,第二请求报文为第二应用程序通过总线发送给第二目标从设备的请求报文,也就是说,第二请求报文来自于第二应用程序,第二请求报文的既定接收方为第二目标从设备。需要说明的是,在本申请实施例中,第一应用程序和第二应用程序可以是同一个应用程序,也可以是不同的应用程序。本申请实施例对此不做限定。第一目标从设备和第二目标从设备可以是同一个从设备,也可以是不同的从设备,本申请实施例对此不做限定。
如前文所述,主设备将待发送的请求报文进行排序,将排序后的待发送请求报文存储在待发送队列中,以便于总线处理完第一请求报文之后,根据待发送队列中的待发送请求报文,确定下一条待处理的请求报文。而第二请求报文为待发送队列中与第一请求报文相邻的后一个请求报文,故而,总线处理完第一请求之后,即可确认第二请求报文为下一条待处理的请求报文。
本申请实施例提供的通信方法,当主设备通过总线将待发送队列中的第一请求报文发送给第一目标从设备时,监控第一目标从设备针对第一请求报文发送的应答报文的应答时间。若该应答时间满足第一预设条件,则判断报文发送序列中是否存在第二请求报 文,若存在,则向第二目标从设备发送第二请求报文。也就是说,利用本申请实施例提供的通信方法,当满足不再允许或不再需要为了处理第一请求报文而需要占用主线的第一预设条件时,主设备自动将第一应用程序占用的总线释放,以便主设备中安装的其它应用程序使用该总线。从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
如前文所述,在本申请实施例中,若主设备中安装有多个应用程序,当存在多条请求报文需要利用总线传输时,主设备可以将待发送的请求报文进行排序,将排序后的待发送请求报文存储在待发送队列中。以便于总线处理完待发送队列中的第一请求报文之后,根据待发送队列中的待发送请求报文,确定下一条处理的请求报文。以下将介绍主设备将待发送的待发送请求报文进行排序,并将排序后的待发送请求报文存储在待发送队列中的具体实现方法。
如前文所述,当应用程序需要利用总线向对应的从设备发送请求报文时,可以先将待发送的请求报文发送给主设备,由主设备对待发送的请求报文进行排序,并将排序后的待发送请求报文存储在待发送队列中。
一般来讲,对多个请求报文进行排序,可以按照主设备接收到应用程序发送的待发送请求报文的时间排序。主设备获取到应用程序发送的待发送请求报文的时间越早,该待发送请求报文在多个待发送请求报文中的排序越靠前,该待发送请求报文通过总线发送至对应的从设备的时间越早。例如,可结合图1进行理解,主设备100于11:30分接收到应用程序110发送的请求报文1,主设备100于当天11:31分接收到应用程序120发送的请求报文2,主设备100于当天11:32分接收到应用程序110发送的请求报文3。则按照主设备100接收到三个待发送请求报文的时间顺序对这三个待发送请求报文进行排序,排序结果为请求报文1、请求报文2、请求报文3。并将请求报文1、请求报文2和请求报文3存储在待发送队列中。当总线处理完上一条请求报文之后,再处理请求报文1,总线处理完请求报文1之后,再处理请求报文2,总线处理完请求报文2之后,再处理请求报文3。
可以理解的是,在实际应用中,一方面,主设备上安装的各个应用程序的重要程度不同,另一方面,各个待发送请求报文的紧急程度不同。因此,若只是按照主设备接收到应用程序发送的请求报文的时间对待发送请求报文进行排序,一方面,不能优先处理重要应用程序对应的待发送请求报文,另一方面,不能优先处理紧急程度高的待发送请求报文。
鉴于此,在本申请实施例中,应用程序在向主设备发送待发送请求报文时,可以根据该待发送请求报文的紧急程度和/或重要程度设置该待发送请求报文的优先级,以便于主设备根据该待发送请求报文的优先级确定该待发送请求报文在多个待发送请求报文中的排序位置,进而确定该待发送请求报文在待发送队列中的存储位置。具体地,应用程序向主设备发送待发送请求报文时,可以将该待发送请求报文的优先级添加到该待发送请求报文中,以便于主设备获取该请求报文的优先级。从而确定该待发送请求报文在多个待发送请求报文中的排序位置,进而确定该待发送请求报文在待发送队列中的存储位置。
但是,考虑到实际应用中,可能存在应用程序恶意竞争总线,将待发送的请求报文的优先级设置的很高,以达到其发送的待发送请求报文被优先处理的目的。鉴于此,在本申请实施例中,主设备接收到应用程序发送的待发送请求报文之后,可以对该待发送请求报文中携带的优先级进行验证,判断该优先级是否在合理的优先级范围内。所谓该优先级在合理的优先级范围内,是指,该优先级在主设备为该应用程序设置的优先级范围之内。并根据对待发送请求报文中携带的优先级验证的结果确定该待发送请求报文在多个待发送请求报文中的排序位置,进而确认该待发送请求报文在待发送队列中的存储位置。
当在主设备中为应用程序设置优先级范围之后,主设备存储该应用程序标识与优先级范围之间的对应关系。因此,为了便于主设备根据应用程序发送的待发送请求报文确定该应用程序对应的优先级范围,应用程序向主设备发送待发送请求报文时,可以将其自身的标识添加到该待发送请求报文中,即,该应用程序向主设备发送的待发送请求报文中,携带有该应用程序的标识,以便于主设备根据该待发送请求报文中携带的应用程序标识,以及该应用程序标识和优先级范围的映射关系,确定该应用程序的优先级范围。
以第一应用程序利用总线向第一目标从设备发送第一请求报文为例进行说明。首先,第一应用程序在安装时,主设备为第一应用程序设置一个优先级范围,并保存第一应用层程序标识和第一应用程序优先级范围之间的映射关系。当第一应用程序向主设备发送第一请求报文时,在第一请求报文中添加该第一请求报文的优先级以及第一应用程序的标识,即第一请求报文中携带有第一请求报文的优先级以及第一应用程序的标识。主设备接收到该第一请求报文之后,获得第一请求报文中携带的第一应用程序的标识,利用第一应用程序的标识和第一应用程序的优先级范围之间的对应关系获取第一应用程序的优先级范围,并判断第一请求报文中携带的第一请求报文的优先级是否在第一应用程序的优先级范围之内,若第一请求报文中携带的第一请求报文的优先级在第一应用程序的优先级范围之内,说明该第一请求报文中携带的第一请求报文的优先级在合理的优先级范围之内。此时,可以根据第一请求报文中携带的第一请求报文的优先级确定第一请求报文在多个待发送请求报文中的排序位置,从而确定第一请求报文在待发送队列中的存储位置。若第一请求报文中携带的第一请求报文的优先级不在第一应用程序的优先级范围之内,则主设备可以为该第一请求报文设置一个在合理优先级范围内的优先级,并根据主设备为该第一请求报文设置的优先级确定第一请求报文在多个待发送请求报文中的排序位置,从而确定第一请求报文在待发送队列中的存储位置。
本申请实施例不具体限定主设备为第一请求报文设置在合理优先级范围内的优先级的具体取值,作为一种示例,主设备可以设置第一应用程序对应的优先级范围中的最高优先级作为第一请求报文的优先级。
需要说明的是,在本申请实施例中,若待发送请求报文的优先级相同,则可以根据主设备接收到待发送请求报文的时间顺序对待发送请求报文进行排序,从而确定待发送请求报文在待发送队列中的存储位置。
需要说明的是,在本申请实施例中,待发送请求报文在待发送队列中的存储位置, 可以表征待发送请求报文在多个待发送请求报文中的排序位置。但是,本申请实施例不具体限定待发送队列的实现方式,例如可以是链表结构。
为方便理解,以下结合具体实例和对本申请实施例提供的主设备将待发送的请求报文进行排序,并将排序后的待发送请求报文存储在待发送队列中的方法进行介绍。
11:30时,待发送队列中的最后一条待发送请求报文正在通过总线发送给相应的从设备,即当前总线处于被占用状态。主设备100于11:31分接收到应用程序110发送的请求报文4,主设备100于当天11:32分接收到应用程序120发送的请求报文5,主设备100于当天11:32分接收到应用程序110发送的请求报文6。其中,请求报文4、请求报文5以及请求报文6中携带的优先级均在合理的优先级范围内,且请求报文4的优先级为5级,请求报文5的优先级为6级,请求报文6的优先级为5级,优先级数值越大,表示优先级越高。则当主设备接收到请求报文4时,由于请求报文4是唯一一条待发送请求报文,故主设备将请求报文4排在待发送请求报文中的第一位;当主设备接收到请求报文5时,由于请求报文5的优先级高于请求报文4,故而主设备将请求报文5排在待发送请求报文中的第一位,将请求报文4排在待发送请求报文中的第二位;当主设备接收到请求报文6时,由于请求报文6的优先级低于请求报文5,故而请求报文6排在请求报文5之后,又因为请求报文6的优先级和请求报文4的优先级相同,但主设备接收到请求报文4的时间比接收到6请求报文的时间早,故而。主设备将请求报文6排在请求报文4之后,即主设备将请求报文5排在待发送请求报文中的第一位,将请求报文4排在待发送请求报文的第二位,将请求报文6排在待发送请求报文的第三位。并根据这三个待发送请求报文的排序确定这三个待发送请求报文在待发送队列中的存储位置。
需要说明的是,对于第一请求报文而言,以上介绍的主设备将第一请求报文进行排序,并将排序后的第一请求报文存储在待发送队列中的具体实现方法,可以在步骤201之前执行。也就是说,在本申请实施例中,当第一请求报文中携带有第一请求报文的优先级时,在步骤201主设备通过总线向第一目标从设备发送待发送队列中的第一请求报文之前,还可以包括步骤A和步骤B。
步骤A:主设备获取与第一请求报文对应的目标应用程序的目标优先级范围。
步骤B:若第一请求报文的优先级在目标应用程序的目标优先级范围内,则根据第一请求报文的优先级确定第一请求报文在待发送队列中的存储位置。
具体地,步骤A在具体实现时,主设备可以根据第一请求报文中携带的目标应用程序的标识,以及目标应用程序标识与目标应用程序的优先级范围之间的映射关系,得到目标应用程序的目标优先级范围。
其中,第一请求报文对应的目标应用程序是指,向主设备发送第一请求报文的应用程序,即,第一应用程序。目标应用程序的目标优先级范围,是指,主设备为目标应用程序设置的优先级范围。即,第一应用程序的优先级范围。目标应用程序的标识,是指,第一应用程序的标识,可以用于唯一标识第一应用程序。
需要说明的是,若第一请求报文的优先级不在第一应用程序的目标优先级范围之内,则主设备可以为该第一请求报文重新确认一个在目标优先级范围内的优先级,并根据主设备为该第一请求报文重新确认的优先级确定第一请求报文在多个待发送请求报文中的 排序位置,从而确定第一请求报文在待发送队列中的存储位置。
比如说,第一请求报文的优先级为6,不在第一应用程序的目标优先级范围(1-3)之内时,可以将预先设定的一个在第一应用程序的目标优先级范围内的优先级,例如2,作为该第一请求报文重新确认的优先级。
本申请实施例提供的主设备将待发送的请求报文进行排序,并将排序后的待发送请求报文存储在待发送队列中的方法,考虑了应用程序重要程度和/或待发送请求报文的紧急程度来对待发送请求报文进行排序,从而使得重要应用程序对应的待发送请求报文能够被优先处理,和/或,紧急程度高的待发送请求报文也能够被优先处理。
如前文所述,一条总线上可以连接一个主设备和多个从设备。当主设备上安装有多个应用程序时,用户期望各个应用程序只能通过总线和被授权的从设备通信。例如,可结合图1进行理解,用户期望应用程序110智能利用RS-485总线300和从设备210通信,而不能和其它从设备进行通信;应用程序120只能利用RS-485总线300和从设备220通信,而不能和其它从设备进行通信;应用程序130可以利用RS-485总线300和从设备230通信,而不能和其它从设备进行通信;应用程序140既智能利用RS-485总线300和从设备240通信以及从设备250通信,不能和从设备210、从设备220以及从设备230通信。
鉴于此,在本申请实施例中,主设备在接收到应用程序发送的待发送请求报文时,还可以验证该待发送的请求报文是否是向该应用程序授权的从设备发送的。若该待发送地请求报文是向该应用程序授权的从设备发送的,才通过总线将该待发送请求报文发送给对应的从设备。也就是说,在本申请实施例中,在步骤201之前,还可以包括步骤301至步骤303。
步骤301:获取第一请求报文对应的目标应用程序的通信地址集合,该通信地址集合中至少包括一个与目标应用程序通信的从设备的通信地址。
本申请实施例中提及的第一请求报文对应的目标应用程序是指,向主设备发送第一请求报文的应用程序,即,第一应用程序。目标应用程序的通信地址集合,是指该目标应用程序的授权从设备的通信地址的集合。可以理解的是,目标应用程序的授权从设备可以为一个从设备,也可以为多个从设备。当目标应用程序的授权的从设备为1个时,目标应用程序的通信地址集合中包括该授权的一个从设备的通信地址,当目标应用程序的授权的从设备为多个时,目标应用程序的通信地址集合中包括授权的多个从设备的通信地址。例如,可结合图1进行理解,若目标应用程序为应用程序110,则目标应用程序的通信地址集合中包括从设备210的通信地址;若目标应用程序为应用程序140,则目标应用程序的通信地址集合中包括从设备240的通信地址以及从设备250的通信地址。
需要说明的是,在步骤301的一种可能的实现方式中,主设备在安装目标应用程序时,可以根据目标应用程序的配置信息确定该目标应用程序的授权的从设备的通信地址,并保存目标应用程序的通信地址集合和目标应用程序的标识的映射关系。当主设备接收到第一请求报文时,可以获取第一请求报文中携带的目标应用程序的标识,并根据目标应用程序的标识和目标应用程序的通信地址集合的映射关系,获得第一请求报文对应的目标应用程序的通信地址集合。
步骤302:从第一请求报文中解析得到第一目标从设备的通信地址。
步骤303:判断第一目标从设备的通信地址是否存在于目标应用程序的通信地址集合中,若存在,则执行步骤201;如果否,则执行步骤304,即丢弃第一请求报文。
关于步骤302和步骤303,需要说明的是,一般来讲,第一请求报文中携带有第一目标从设备的通信地址,以便第一目标从设备根据该第一请求报文中携带的第一目标从设备的通信地址,确认该第一请求报文是发送给第一目标从设备的请求报文,从而对该第一请求报文做出响应。
当主设备从第一请求报文中解析得到第一目标从设备的通信地址之后,若该第一目标从设备的通信地址存在于目标应用程序的通信地址集合中,则说明第一目标从设备是目标应用程序的授权的从设备。故而,可以执行步骤201,通过总线向第一目标从设备发送第一请求报文。若该第一目标从设备的通信地址不存在于目标应用程序的通信地址集合中,则说明第一目标从设备不是目标应用程序的授权的从设备,也就是说,目标应用程序不能和第一目标从设备进行通信,此时,可以丢弃该第一请求报文。
需要说明的是,在实际应用中,目标应用程序与第一目标从设备进行通信时,发送的第一请求报文需要符合一定的报文发送规则。如果目标应用程序未按照规定的报文发送规则向第一目标从设备发送第一请求报文,即使第一请求报文通过总线发送出去,第一目标从设备也不能正确解析该第一请求报文,从而导致目标应用程序和第一目标从设备通信失败。
在本申请实施例中,目标应用程序的报文发送规则可以包括:帧头、帧尾、帧长度、目标应用程序的标识、第一目标从设备的通信地址等信息中的部分或全部信息,以及具体的组帧方式。本申请实施例不具体限定目标应用程序的报文发送规则,具体报文发送规则可以根据目标应用程序的具体类型确定。
因此,步骤302在具体实现时,主设备可以先获取目标应用程序对应的报文发送规则,判断第一请求报文的报文发送规则是否满足目标应用程序对应的报文发送规则,如果是,则从第一请求报文中解析得到第一目标从设备的通信地址。
主设备获取目标应用程序对应的报文发送规则的方式与主设备获取目标应用程序的通信地址集合的方式类似,即主设备在安装目标应用程序时,预先保存目标应用程序标识和目标应用程序对应的报文发送规则之间的映射关系,主设备接收到第一请求报文之后,获取第一请求报文中携带的目标应用程序标识,利用目标应用程序标识和目标应用程序对应的报文发送规则之间的映射关系,得到目标应用程序对应的报文发送规则。
本申请实施例提供的方法,主设备可以对应用程序发送的待发送的请求报文进行验证,只有当待发送的请求报文是向该应用程序授权的从设备发送的,才通过总线将该待发送请求报文发送给对应的从设备。若待发送的请求报文不是向该应用程序授权的从设备发送的,则丢弃该待发送请求报文,以便于其他待发送请求报文利用总线与对应的从设备通信。提高总线利用率和其它应用程序的通信及时性。
需要说明的是,在实际应用中,当主设备安装有多个应用程序时,一般来讲,各个应用程序对通信资源的使用情况应该比较均匀,很少出现一些应用程序过多的占用通信资源的情况,若一些应用程序过多的占用通信资源,则该应用程序可能是流氓应用程 序,应该禁止该流氓应用程序继续占用通信资源。鉴于此,在本申请实施例中,主设备还可以监控通信资源的使用情况,当发现流氓应用程序时,禁止该流氓应用程序继续占用通信资源。
以监控第一请求报文对应的应用程序是否为流氓应用为例,介绍主设备监控通信资源的使用情况的具体方法。该方法可以通过步骤401到步骤402实现。
步骤401:统计在第四预设时间段内发送第一请求报文对应的通信资源使用信息。
需要说明的是,本申请实施例中提及的通信资源使用信息是指,为了发送第一请求报文而对通信资源进行使用的信息。例如,通信资源使用信息可以为第一请求报文的数据量、针对第一请求报文发送的应答报文的数据量、从第一请求报文被发送之后到停止获取该应答报文所花费的时间、从开始获取该应答报文到停止获取该应答报文所花费的时间,以及在第一请求报文被发送的次数等中的一种或多种。
其中,第一请求报文的数据量可以是第一请求报文的字节总数;应答报文的数据量可以是应答报文的字节总数;从第一请求报文被发送之后到停止获取该应答报文所花费的时间,是指,第一请求报文对应的应用程序与第一目标从设备完成一次交互所使用的时间,可以表征第一请求报文对应的应用程序与第一目标从设备交互时对总线的占用情况;从开始获取该应答报文到停止获取该应答报文所花费的时间,是指,第一目标从设备发送应答报文所使用的时间,可以表征第一目标从设备发送应答报文时对总线的占用情况;第一请求报文被发送的次数,是指,总线用于发送第一请求报文的次数,可以表征第一请求报文对应的应用程序使用总线的频率。
需要说明的是,本申请实施例不具体限定第四预设时间段,第四预设时间段可以根据实际情况具体设置。例如,第四预设时间段所占的时间长度为1小时,第四预设时间段可以为上午10:00至当天上午11:00、上午11:00至当天上午12:00等等;又如,第四预设时间段所占的时间长度为1小时,第四预设时间段为从发送第一请求报文时开始计时,直到累计计时为1小时之间的时间段。
可以理解的是,为了避免过多的占用存储资源,在统计得到在第四预设时间段内发送第一请求报文对应的通信资源使用信息之后,可以将该通信资源使用信息删除。
步骤402:若在第四预设时间段内发送第一请求报文对应的通信资源使用信息满足不合理使用条件,则禁止与第一请求报文对应的应用程序利用总线再次发送第一请求报文。
可以理解的是,在第四预设时间段内发送第一请求报文对应的通信资源使用信息满足不合理使用条件,可以是该通信资源使用信息超过了预设阈值。例如,在第四预设时间段内发送第一请求报文对应的通信资源使用信息满足不合理使用条件,可以是第一请求报文的总数据量大于第一预设数据量阈值;又如,在第四预设时间段内发送第一请求报文对应的通信资源使用信息满足不合理使用条件,可以是针对第一请求报文发送的应答报文的总数据量大于第二预设数据量阈值;再如,在第四预设时间段内发送第一请求报文对应的通信资源使用信息满足不合理使用条件,可以是从第一请求报文被发送之后到停止获取该应答报文所花费的总时间大于第一预设时间阈值;再如,在第四预设时间段内发送第一请求报文对应的通信资源使用信息满足不合理使用条件,可以是从开始获取该应答报文到停止获取该应答报文所花费的总时间大于第二预设时间阈值;再如,在第四预设时间段内发送 第一请求报文对应的通信资源使用信息满足不合理使用条件,可以是第一请求报文被发送的次数大于预设次数阈值。
需要说明的是,对于发送其他请求报文时对应的通信资源信息的统计方法,与发送第一请求报文时对应的对通信资源信息地统计方法相同;对应的,判断发送其他请求报文对应的应用程序是否过多占用通信资源的方法,与判断发送第一请求报文对应的应用程序是否过多占用通信资源的方法相同;当发送其他请求报文对应的应用程序过多占用通信资源时的处理措施,与发送第一请求报文对应的应用程序过多占用通信资源时的处理措施相同。在此不再一一赘述。
由此可见,本申请实施例提供的方法,主设备还可以监控通信资源的使用情况,当发现流氓应用程序时,禁止该流氓应用程序继续占用通信资源。
可以理解的是,在实际应用中,主设备上安装的应用程序和对应的从设备进行通信时,可能会出现异常情况。例如,由于从设备故障导致总线一直被不合理占用。此时,主设备还可以针对该异常情况执行相应的处理措施。
具体地,在一种可能的实现方式中,可以从第一请求报文发送的时刻开始计时,若在第二预设时间段内未接收到完整的应答报文,则进行记录、报警和/或累计未接收到完整的应答报文的次数。
需要说明的是,若从第一请求报文发送的时刻开始计时,在第二预设时间段内未接收到完整的应答报文。则说明,总线被第一应用程序占用的时间过长。总线被第一应用程序占用的时间过长的原因有多种。
第一种原因:第一应用程序发送的第一请求报文的数据量很大,导致发送该应答报文的时间过长。故而,总线一直被第一应用程序占用。
第二种原因:第一目标从设备发送的应答报文数据量很大,导致发送该应答报文的时间过长。故而,总线一直被第一应用程序占用。
第三种原因:第一请求报文发送完成之后,第一目标从设备没有立即响应,导致第一目标从设备发送的响应报文未在第二预设时间段内发送完成。
无论是以上三种原因中的哪一种导致第一应用程序对总线的不合理占用,都会导致其它应用程序无法使用总线与对应的从设备进行通信,从而影响了其它应用程序的通信及时性。
因此,在本申请实施例中,对于这种总线被不合理占用的异常情况,在第一种可能的实现方式中,主设备可以对该异常情况进行记录,例如,记录该异常情况对应的第一应用程序的标识、第一请求报文、该第一请求报文对应的第一目标从设备的标识以及第一目标从设备针对第一请求报文发送的应答报文等信息,以便于对总线异常情况进行维护修复时,通过查看该记录信息,从而确定引起总线异常的原因。
在第二种可能的实现方式中,主设备可以报警,以提示用户总线出现异常,以便于用户及时对总线异常情况进行处理。
在第三种可能的实现方式中,主设备可以累计未接收到第一目标从设备针对第一请求报文发送的完整的应答报文的次数,从而确定第一应用程序导致总线异常的次数。
在第四种可能的实现方式中,主设备可以禁止第一应用程序利用总线与第一目标从设 备进行通信,从而防止第一应用程序利用总线进行通信从而导致总线异常。
需要说明的是,当第一应用程序不合理的占用总线时,主设备可以将以上四种实现方式全部执行,也可以执行以上四种实现方式中的一种或多种实现方式,对此,本申请实施例不做具体限定。
需要说明的是,关于如何判断是否接收到了来自第一目标从设备发送的完整的应答报文,可以参考上文中“第二种情况”中的描述部分,在此不再赘述。
以上内容对本申请实施例提供的通信方法进行了描述,请结合图5进行理解,图5为本申请实施例提供的一个应用场景示意图。在该场景下,主设备100为物联网关,网关与多个从设备通过RS-485总线300进行通信,从设备分别为从设备260、从设备270、从设备280和从设备290。物联网关100上安装有多个应用程序,分别为应用程序511、应用程序512、应用程序521和应用程序522。
需要说明的是,物联网关100上安装的多个应用程序可能是由不同的厂商开发的,故而各个应用程序的稳定性和安全性可能不同。故而,在实际应用中,物联网关100往往将应用程序安装到虚拟机中,与物联网关的主系统530隔离,从而防止因为应用程序的缺陷引发主系统530故障。
容器技术是一种常用的将应用程序安装到虚拟机中的技术。容器技术是指,将物联网关中的一部分资源划分出来,用于安装应用程序,这些被划分出来的资源可以形成一个容器,可结合图5进行理解,图5中的510是一个容器,520也是一个容器。容器510和容器520中分别有自己的虚拟文件系统以及相关的资源设备。在物联网关100中,安装了两个容器510和520,容器510和520分别安装了两个应用程序,其中,容器510中安装了应用程序511和应用程序512,容器520中安装了应用程序521和应用程序522。这四个应用程序均需要访问RS-485通信接口。
图5中,容器510中的“RS-485设备驱动”513和容器520中的“RS-485设备驱动”523全部映射到主系统中的“虚拟RS-485设备驱动”531,也就是说,容器510和520中没有真正实现RS-485设备驱动,而是引用了主系统中的“虚拟RS-485设备驱动”531的实现,因此,对容器中的“RS-485设备驱动”513的接口调用,实际上调用的是主系统中“虚拟RS-485设备驱动”531的对应接口。
本申请实施例提供的交互方法,可以由图5中所述的“虚拟RS-485设备驱动”531实现。在该场景下,待发送队列中存储有两条待发送请求报文,分别为第一请求报文和第二请求报文。第一请求报文存储在第二请求报文之前。第一请求报文为应用程序511发送给第一目标从设备260的请求报文,第二请求报文为应用程序521发送给第二目标从设备290的请求报文。下面结合图5所示的应用场景以及图6对本申请实施例提供的通信方法进行描述。
步骤601:虚拟RS-485设备驱动531根据第一请求报文中携带的目标应用程序(即应用程序511)的标识,确定目标应用程序对应的报文发送规则,并确定第一请求报文满足该报文发送规则。
步骤602:虚拟RS-485设备驱动531从第一请求报文中解析得到第一目标从设备的通 信地址;根据第一请求报文中携带的目标应用程序的标识,确定目标应用程序的通信地址集合,确定第一目标从设备260的通信地址存在于第一目标应用程序的通信地址集合中。
步骤603:虚拟RS-485设备驱动531调用传统RS-485设备驱动532,利用RS-485总线300向第一目标从设备260发送第一请求报文。
步骤604:第一目标从设备260解析接收到的第一请求报文,确定第一请求报文是发送给自身的请求报文。
步骤605:第一目标从设备260利用RS-485总线300向目标应用程序发送应答报文。
步骤606:虚拟RS-485设备驱动531从获取到该应答报文中其中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个最小传输单位的数据,确定应答报文接收完毕。
步骤607:虚拟RS-485设备驱动531在待发送队列中查询到第二请求报文。
步骤608:虚拟RS-485设备驱动531调用传统RS-485设备驱动532,利用RS-485总线300向第二目标从设备290发送第二请求报文。
需要说明的是,传统RS-485设备驱动532可以实现将待发送请求报文进行格式转换,转换成符合RS-485通信协议的数据,并通过RS-485总线300发送出去的功能。
需要说明的是,以上场景实施例只是一种示例性的说明,本申请实施例提供的通信方法还可以应用于其它场景,在此不再一一列举说明。
需要说明的是,虽然在以上场景中,应用程序安装在容器中,但是,本申请实施例提供的方法,并不限于以上场景,应用程序不安装在容器中时,依然适用本申请实施例的方案。
为便于更好的实施本申请实施例的上述方案,下面还提供用于实施上述方案的相关装置。
请参考图7所示,本申请实施例提供的一种通信装置700,该通信装置700具体对应于上述提供的通信方法的功能。该通信装置700的功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括一个或多个与上述功能相对应的单元,单元可以是软件和/或硬件。该装置700可以包括:第一请求报文发送单元710和应答报文获取单元720。
第一请求报文发送单元710,用于调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备;
应答报文获取单元720,用于获取第一目标从设备针对第一请求报文发送的应答报文的应答时间,若应答时间满足第一预设条件,且发送队列中存在第二请求报文,则调用总线驱动接口向第二目标从设备发送第二请求报文,第二请求报文为待发送队列中与第一请求报文相邻的后一个请求报文。
在一种可能的实现中,第一预设条件,包括:
从第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到应答报文;
或者,
从第一请求报文发送的时刻开始计时,在第二预设时间段内获取到应答报文的帧尾;
或者,
从获取到应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个最小传输单位的数据。
在一种可能的实现中,第一请求报文中包括第一请求报文的优先级;
该装置700还包括:
存储位置确定单元,用于在第一请求报文被发送之前,根据第一请求报文的优先级确定第一请求报文在待发送队列中的存储位置。
在一种可能的实现中,第一请求报文中还包括目标应用程序的标识,存储位置确定单元,具体用于
根据目标应用程序的标识,以及应用程序标识与优先级范围之间的对应关系,得到目标应用程序的目标优先级范围;
当第一请求报文的优先级在目标优先级范围内时,根据第一请求报文的优先级确定第一请求报文在待发送队列中的存储位置。
在一种可能的实现中,装置700还包括:通信地址集合获取单元,通信地址解析单元;
通信地址集合获取单元,用于获取第一请求报文对应的目标应用程序的通信地址集合,通信地址集合包括至少一个与目标应用程序通信的从设备的通信地址;
通信地址解析单元,用于从第一请求报文中解析得到第一目标从设备的通信地址;
第一请求报文发送单元710,用于当第一目标从设备的通信地址存在于通信地址集合中时,执行通过总线将待发送队列中的第一请求报文发送给第一目标从设备的步骤。
在一种可能的实现中,通信地址解析单元包括:报文发送规则获取子单元和通信地址获得子单元;
报文发送规则获取子单元,用于获取目标应用程序对应的报文发送规则;
报文发送规则获取子单元,用于当第一请求报文符合报文发送规则时,从第一请求报文中解析得到第一目标从设备的通信地址。
在一种可能的实现中,装置700还包括:资源使用信息统计单元和禁止使用总线单元;
资源使用信息统计单元,用于统计在第四预设时间段内发送第一请求报文对应的通信资源使用信息;
禁止使用总线单元,用于当通信资源使用信息满足不合理使用条件时,禁止与第一请求报文对应的应用程序利用总线再次发送第一请求报文。
在一种可能的实现中,通信资源使用参数至少包括以下任意一种:
第一请求报文的数据量、应答报文的数据量、从第一请求报文被发送之后到停止获取应答报文所花费的时间、从开始获取应答报文到停止获取应答报文所花费的时间,以及第一请求报文被发送的次数。
在一种可能的实现中,若在第二预设时间段内未接收到完整的应答报文,则装置700还包括:记录单元;
记录单元,用于进行记录、报警和/或累计未接收到完整的应答报文的次数。
利用本申请实施例提供的通信装置,当满足不再允许或不再需要为了处理第一请求报文而需要占用主线的第一预设条件时,主设备自动将第一应用程序占用的总线释放, 以便主设备中安装的其它应用程序使用该总线。从而避免了主设备中安装的某个应用程序对总线的占用时间过长,从而影响其它应用程序的通信及时性的问题,提高用户体验。
需要说明的是,上述装置各模块/单元之间的信息交互、执行过程等内容,由于与本申请实施例方法实施例基于同一构思,其带来的技术效果与本申请实施例方法实施例相同,具体内容可参见本申请实施例前述所示的方法实施例中的叙述,此处不再赘述。
接下来介绍本申请实施例中的通信设备。请参阅图8所示,通信设备800包括:处理器810、通信接口820和和存储器830。其中通信设备800中的处理器810的数量可以一个或多个,图8中以一个处理器为例。本申请实施例中,处理器810、通信接口820和存储器830可通过总线系统或其它方式连接,其中,图8中以通过总线系统840连接为例。
处理器810可以是中央处理器(central processing unit,CPU),网络处理器(network processor,NP)或者CPU和NP的组合。处理器810还可以进一步包括硬件芯片。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,ASIC),可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD),现场可编程逻辑门阵列(field-programmable gate array,FPGA),通用阵列逻辑(generic array logic,GAL)或其任意组合。
在申请实施例中,通信接口820可以为支持RS-485通信协议的通信接口。通信接口820可以集成接收和发送数据报文的功能。
存储器830可以包括易失性存储器(英文:volatile memory),例如随机存取存储器(random-access memory,RAM);存储器830也可以包括非易失性存储器(英文:non-volatile memory),例如快闪存储器(英文:flash memory),硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器410还可以包括上述种类的存储器的组合。
存储器830用于存储待发送队列,第一预设时间,第二预设时间,第三预设时间等。
可选地,存储器830存储有操作系统和程序、可执行模块或者数据结构,或者它们的子集,或者它们的扩展集,其中,程序可包括各种操作指令,用于实现各种操作。操作系统可包括各种系统程序,用于实现各种基础业务以及处理基于硬件的任务。处理器810可以读取存储器830中的程序,实现本申请实施例提供的通信方法。
总线系统840可以是外设部件互连标准(peripheral component interconnect,PCI)总线或扩展工业标准结构(extended industry standard architecture,EISA)总线等。总线系统840可以分为地址总线、数据总线、控制总线等。为便于表示,图8中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。本申请实施例还提供一种计算机可读存储介质,包括指令,当其在计算机上运行时,使得计算机执行以上方法实施例提供的通信方法。
本申请实施例还提供一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行以上方法实施例提供的通信方法。
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统,装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单 元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,以上实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。
Claims (16)
- 一种通信方法,其特征在于,所述方法应用于主设备,所述方法包括:调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备;获取所述第一目标从设备针对所述第一请求报文发送的应答报文的应答时间,若所述应答时间满足第一预设条件,且所述发送队列中存在第二请求报文,则调用所述总线驱动接口向第二目标从设备发送所述第二请求报文,所述第二请求报文为所述待发送队列中与所述第一请求报文相邻的后一个请求报文。
- 根据权利要求1所述的方法,其特征在于,所述第一预设条件,包括:从所述第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到所述应答报文;或者,从所述第一请求报文发送的时刻开始计时,在第二预设时间段内获取到所述应答报文的帧尾;或者,从获取到所述应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个所述最小传输单位的数据。
- 根据权利要求1或2所述的方法,其特征在于,所述第一请求报文中包括所述第一请求报文的优先级;在所述第一请求报文被发送之前,所述方法还包括:根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
- 根据权利要求3所述的方法,其特征在于,所述第一请求报文中还包括目标应用程序的标识,所述根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置包括:根据所述目标应用程序的标识,以及应用程序标识与优先级范围之间的对应关系,得到所述目标应用程序的目标优先级范围;若所述第一请求报文的优先级在所述目标优先级范围内,则根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
- 根据权利要求1至4任一项所述的方法,其特征在于,所述方法还包括:获取所述第一请求报文对应的目标应用程序的通信地址集合,所述通信地址集合包括至少一个与所述目标应用程序通信的从设备的通信地址;从所述第一请求报文中解析得到所述第一目标从设备的通信地址;若所述第一目标从设备的通信地址存在于所述通信地址集合中,则执行所述通过总线将待发送队列中的第一请求报文发送给第一目标从设备的步骤。
- 根据权利要求5所述的方法,其特征在于,所述从所述第一请求报文中解析得到所述第一目标从设备的通信地址包括:获取所述目标应用程序对应的报文发送规则;若所述第一请求报文符合所述报文发送规则,则从所述第一请求报文中解析得到所述第一目标从设备的通信地址。
- 根据权利要求1至6任一项所述的方法,其特征在于,所述方法还包括:统计在第四预设时间段内发送所述第一请求报文对应的通信资源使用信息;若所述通信资源使用信息满足不合理使用条件,则禁止与所述第一请求报文对应的应用程序利用所述总线再次发送所述第一请求报文。
- 根据权利要求7所述的方法,其特征在于,所述通信资源使用参数至少包括以下任意一种:所述第一请求报文的数据量、所述应答报文的数据量、从所述第一请求报文被发送之后到停止获取所述应答报文所花费的时间、从开始获取所述应答报文到停止获取所述应答报文所花费的时间,以及所述第一请求报文被发送的次数。
- 根据权利要求2所述的方法,其特征在于,若在第二预设时间段内未接收到完整的所述应答报文,则所述方法还包括:进行记录、报警和/或累计未接收到完整的应答报文的次数。
- 一种通信装置,其特征在于,所述装置应用于主设备,所述装置包括:第一请求报文发送单元,用于调用总线驱动接口将待发送队列中的第一请求报文发送给第一目标从设备;应答报文获取单元,用于获取所述第一目标从设备针对所述第一请求报文发送的应答报文的应答时间,若所述应答时间满足第一预设条件,且所述发送队列中存在第二请求报文,则调用所述总线驱动接口向第二目标从设备发送所述第二请求报文,所述第二请求报文为所述待发送队列中与所述第一请求报文相邻的后一个请求报文。
- 根据权利要求10所述的装置,其特征在于,所述第一预设条件,包括:从所述第一请求报文发送的时刻开始计时,在第一预设时间段内未接收到所述应答报文;或者,从所述第一请求报文发送的时刻开始计时,在第二预设时间段内获取到所述应答报文的帧尾;或者,从获取到所述应答报文中一个最小传输单位的数据的时刻开始计时,在第三预设时间段内未接收到下一个所述最小传输单位的数据。
- 根据权利要求10或11所述的装置,其特征在于,所述第一请求报文中包括所述第一请求报文的优先级;所述装置还包括:存储位置确定单元,用于在所述第一请求报文被发送之前,根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
- 根据权利要求12所述的装置,其特征在于,所述第一请求报文中还包括目标应用程序的标识,所述存储位置确定单元包括:目标优先级范围得到子单元和存储位置确定 子单元;所述目标优先级范围得到子单元,用于根据所述目标应用程序的标识,以及应用程序标识与优先级范围之间的对应关系,得到所述目标应用程序的目标优先级范围;所述目标优先级范围得到子单元,用于当所述第一请求报文的优先级在所述目标优先级范围内时,根据所述第一请求报文的优先级确定所述第一请求报文在所述待发送队列中的存储位置。
- 根据权利要求10至13任一项所述的装置,其特征在于,所述装置还包括:通信地址集合获取单元,通信地址解析单元;所述通信地址集合获取单元,用于获取所述第一请求报文对应的目标应用程序的通信地址集合,所述通信地址集合包括至少一个与所述目标应用程序通信的从设备的通信地址;所述通信地址解析单元,用于从所述第一请求报文中解析得到所述第一目标从设备的通信地址;所述第一请求报文发送单元,用于当所述第一目标从设备的通信地址存在于所述通信地址集合中时,执行所述通过总线将待发送队列中的第一请求报文发送给第一目标从设备的步骤。
- 根据权利要求14所述的装置,其特征在于,所述通信地址解析单元,具体用于获取所述目标应用程序对应的报文发送规则;当所述第一请求报文符合所述报文发送规则时,从所述第一请求报文中解析得到所述第一目标从设备的通信地址。
- 根据权利要求10所述的装置,其特征在于,所述装置还包括:资源使用信息统计单元和禁止使用总线单元;所述资源使用信息统计单元,用于统计在第四预设时间段内发送所述第一请求报文对应的通信资源使用信息;所述禁止使用总线单元,用于当所述通信资源使用信息满足不合理使用条件时,禁止与所述第一请求报文对应的应用程序利用所述总线再次发送所述第一请求报文。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810241054.5A CN110300040B (zh) | 2018-03-22 | 2018-03-22 | 一种通信方法及相关设备 |
CN201810241054.5 | 2018-03-22 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2019179384A1 true WO2019179384A1 (zh) | 2019-09-26 |
Family
ID=67986720
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2019/078438 WO2019179384A1 (zh) | 2018-03-22 | 2019-03-18 | 一种通信方法及相关设备 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN110300040B (zh) |
WO (1) | WO2019179384A1 (zh) |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110990044A (zh) * | 2019-11-12 | 2020-04-10 | 中国航发南方工业有限公司 | 在应用编程方法、计算机可读取的存储介质 |
CN112788265A (zh) * | 2019-11-11 | 2021-05-11 | 浙江宇视科技有限公司 | 录像数据保存方法、装置、图像采集设备及可读存储介质 |
CN112838992A (zh) * | 2019-11-22 | 2021-05-25 | 华为技术有限公司 | 报文调度方法及网络设备 |
CN113076178A (zh) * | 2021-02-25 | 2021-07-06 | 厦门科灿信息技术有限公司 | 报文存储方法、装置及设备 |
CN114257282A (zh) * | 2021-12-17 | 2022-03-29 | 锐捷网络股份有限公司 | 报文发送方法、装置、智能终端和存储介质 |
CN116233039A (zh) * | 2023-01-13 | 2023-06-06 | 北京信而泰科技股份有限公司 | 报文发送方法、装置、设备和可读存储介质 |
CN118672807A (zh) * | 2024-08-21 | 2024-09-20 | 格创通信(浙江)有限公司 | 一种报文分类缓存调度方法、装置、芯片及电子设备 |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111045980A (zh) * | 2019-12-24 | 2020-04-21 | 广东嘉泰智能技术有限公司 | 一种多核处理器 |
CN113064723B (zh) * | 2021-03-23 | 2024-05-24 | 瀚云科技有限公司 | 存储介质、电子设备、总线资源分配方法及装置 |
CN114978798B (zh) * | 2022-05-23 | 2024-02-27 | 重庆奥普泰通信技术有限公司 | 串行通信方法、装置及板卡 |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN202906949U (zh) * | 2012-11-21 | 2013-04-24 | 福州昌晖自动化系统有限公司 | 一种rs485双主机通讯透传模块 |
CN106569897A (zh) * | 2016-11-07 | 2017-04-19 | 许继集团有限公司 | 基于协作式多任务调度机制的共享总线的轮询方法与装置 |
US9798688B1 (en) * | 2013-03-15 | 2017-10-24 | Bitmicro Networks, Inc. | Bus arbitration with routing and failover mechanism |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8094677B2 (en) * | 2007-02-27 | 2012-01-10 | Integrated Device Technology, Inc. | Multi-bus structure for optimizing system performance of a serial buffer |
CN100525233C (zh) * | 2007-08-28 | 2009-08-05 | 杭州电子科技大学 | 一种基于can总线的信号实时性处理方法 |
CN103077141B (zh) * | 2012-12-26 | 2015-08-26 | 西安交通大学 | 一种基于amba总线的自适应实时加权优先仲裁方法及仲裁器 |
-
2018
- 2018-03-22 CN CN201810241054.5A patent/CN110300040B/zh active Active
-
2019
- 2019-03-18 WO PCT/CN2019/078438 patent/WO2019179384A1/zh active Application Filing
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN202906949U (zh) * | 2012-11-21 | 2013-04-24 | 福州昌晖自动化系统有限公司 | 一种rs485双主机通讯透传模块 |
US9798688B1 (en) * | 2013-03-15 | 2017-10-24 | Bitmicro Networks, Inc. | Bus arbitration with routing and failover mechanism |
CN106569897A (zh) * | 2016-11-07 | 2017-04-19 | 许继集团有限公司 | 基于协作式多任务调度机制的共享总线的轮询方法与装置 |
Cited By (10)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112788265A (zh) * | 2019-11-11 | 2021-05-11 | 浙江宇视科技有限公司 | 录像数据保存方法、装置、图像采集设备及可读存储介质 |
CN112788265B (zh) * | 2019-11-11 | 2024-02-02 | 浙江宇视科技有限公司 | 录像数据保存方法、装置、图像采集设备及可读存储介质 |
CN110990044A (zh) * | 2019-11-12 | 2020-04-10 | 中国航发南方工业有限公司 | 在应用编程方法、计算机可读取的存储介质 |
CN110990044B (zh) * | 2019-11-12 | 2023-06-30 | 中国航发南方工业有限公司 | 在应用编程方法、计算机可读取的存储介质 |
CN112838992A (zh) * | 2019-11-22 | 2021-05-25 | 华为技术有限公司 | 报文调度方法及网络设备 |
CN113076178A (zh) * | 2021-02-25 | 2021-07-06 | 厦门科灿信息技术有限公司 | 报文存储方法、装置及设备 |
CN113076178B (zh) * | 2021-02-25 | 2024-01-02 | 厦门科灿信息技术有限公司 | 报文存储方法、装置及设备 |
CN114257282A (zh) * | 2021-12-17 | 2022-03-29 | 锐捷网络股份有限公司 | 报文发送方法、装置、智能终端和存储介质 |
CN116233039A (zh) * | 2023-01-13 | 2023-06-06 | 北京信而泰科技股份有限公司 | 报文发送方法、装置、设备和可读存储介质 |
CN118672807A (zh) * | 2024-08-21 | 2024-09-20 | 格创通信(浙江)有限公司 | 一种报文分类缓存调度方法、装置、芯片及电子设备 |
Also Published As
Publication number | Publication date |
---|---|
CN110300040A (zh) | 2019-10-01 |
CN110300040B (zh) | 2021-10-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2019179384A1 (zh) | 一种通信方法及相关设备 | |
US20200401551A1 (en) | Methods and systems for accessing host memory through non-volatile memory over fabric bridging with direct target access | |
CN107547589B (zh) | 一种数据采集处理方法以及装置 | |
WO2020052605A1 (zh) | 一种网络切片的选择方法及装置 | |
US20130159466A1 (en) | Vehicular communication control apparatus | |
US10848366B2 (en) | Network function management method, management unit, and system | |
US20130297774A1 (en) | Avoiding delayed data | |
TW201800959A (zh) | 用於物聯網的智能設備控制方法、裝置和設備 | |
WO2024148833A1 (zh) | 一种容器多网卡网络配置方法、装置、设备及存储介质 | |
EP4030810A1 (en) | Method and device for confirming in-situ flow information telemetry capability | |
WO2021134418A1 (zh) | 一种数据校验方法及装置 | |
US20130219052A1 (en) | Dynamic configuration of interconnected devices for measuring performance characteristics in a network | |
CN108718335A (zh) | 一种负载均衡方法、装置、Web服务器及存储介质 | |
CN109818977B (zh) | 一种接入服务器通信优化方法、接入服务器以及通信系统 | |
CN113268446B (zh) | 用于多种机载总线接入的信息处理方法及装置 | |
WO2016011819A1 (zh) | 一种光网络单元业务开通方法、装置及存储介质 | |
WO2024032426A1 (zh) | 一种数据处理方法、网络接口卡、电子设备及存储介质 | |
US7870251B2 (en) | Devices, methods, and computer program products for real-time resource capacity management | |
CN110222084B (zh) | 热点设备监控信息的上报方法及装置、存储介质、终端 | |
CN108804152B (zh) | 配置参数的调节方法及装置 | |
CN108156086B (zh) | 一种策略规则下发方法及装置 | |
CN105915591A (zh) | 访问控制方法和装置 | |
CN107171915B (zh) | 一种通信协议的变更方法及装置 | |
WO2017016300A1 (zh) | 令牌申请处理方法、装置和计算机存储介质 | |
CN108600044B (zh) | 一种接口状态获取方法、装置及设备 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 19771440 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 19771440 Country of ref document: EP Kind code of ref document: A1 |