Real-time priority scheduling method and system for can 2.0 data frame

The CAN2.0 data frame real-time priority scheduling method, which adopts adaptive compression coding and dynamic arbitration sorting, solves the problem of inaccurate time slot resource allocation in the CAN bus scheduling method, and realizes real-time transmission of key data and efficient utilization of bus resources.

CN121486129BActive Publication Date: 2026-04-10JIYA LANGFANG ELECTRONICS CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-02
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Existing CAN bus scheduling methods lack the ability to perceive the characteristics of data content, resulting in inaccurate allocation of time slot resources, affecting the reliability and real-time performance of critical data transmission, especially in scenarios where data compression effects fluctuate greatly, which can easily lead to idle or insufficient resources.

Method used

By acquiring the string data to be sent, extracting the content type identifier and redundancy features, performing adaptive compression coding, calculating the compression ratio parameter, and predicting the time slot demand based on the historical compression ratio sliding window and exponential weighted moving average algorithm, constructing an inter-frame priority sequence, and performing dynamic arbitration sorting and priority adjustment to ensure the reasonable allocation of time slot resources.

Benefits of technology

This system satisfies the real-time requirements of different types of data, avoids the starvation problem caused by long-term waiting of low-priority data, ensures the fairness and real-time performance of system scheduling, and improves the utilization efficiency of bus resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121486129B_ABST
    Figure CN121486129B_ABST
Patent Text Reader

Abstract

The application provides a CAN2.0 data frame real-time priority scheduling method and system, relates to the technical field of distributed control, and comprises the following steps: obtaining string data to be sent, extracting content type identification and redundancy characteristics, performing adaptive compression coding, maintaining a historical compression ratio sliding window and calculating a compression ratio prediction value; determining a time slot continuity requirement level according to the content type identification, calculating a time slot demand amount in combination with the compression ratio prediction value and allocating a time slot resource set; framing the coded data and constructing an inter-frame priority sequence; inserting the data frame into a sending queue, calculating an effective priority value based on the inter-frame priority sequence and a waiting time length to perform arbitration sorting, and sequentially sending under the constraint of the time slot resource set; and when the actual framing quantity is less than the estimated value, allocating the saved time slot resources to target data with the largest priority aging increment. The application improves bus bandwidth utilization and data transmission real-time performance, and optimizes multi-frame scheduling fairness.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to distributed control technology, in particular to a CAN2.0 data frame real-time priority scheduling method and system. BACKGROUND

[0002] CAN bus is a mature fieldbus technology, widely used in automotive electronics, industrial control, intelligent devices and other fields. The existing CAN bus scheduling method lacks the ability to perceive the characteristics of data content, and uses a unified processing strategy for all types of data, which reduces the overall transmission efficiency.

[0003] The prior art uses a fixed or empirical estimation method when allocating time slot resources, which cannot accurately predict the number of transmission time slots required, especially in scenarios where data compression effect fluctuates greatly, which can easily lead to problems such as idle resources due to excessive allocation of time slot resources, or transmission interruption due to insufficient allocation, and lacks a differentiated processing mechanism for the continuity requirements of different content types, affecting the reliability and real-time performance of critical data transmission. SUMMARY

[0004] The embodiments of the present application provide a CAN2.0 data frame real-time priority scheduling method and system, which can solve the problems in the prior art.

[0005] In a first aspect of the embodiments of the present application, a CAN2.0 data frame real-time priority scheduling method is provided, comprising:

[0006] Obtain the string data to be sent, extract the content type identifier and the redundancy feature, perform adaptive compression encoding based on the redundancy feature to obtain the encoded data and the compression ratio parameter; maintain a historical compression ratio sliding window corresponding to the content type identifier, add the compression ratio parameter to the historical compression ratio sliding window, and calculate the compression ratio prediction value;

[0007] Determine the time slot continuity requirement level according to the content type identifier, combine the compression ratio prediction value to calculate the time slot demand, and allocate a time slot resource set on the bus time axis;

[0008] Frame the encoded data into multiple data frames, and construct an inter-frame priority sequence for the data frames;

[0009] Insert the data frames into a sending queue, calculate the effective priority value of each data frame based on the inter-frame priority sequence and the waiting time, arbitrate and sort according to the effective priority value; under the constraint of the time slot resource set, execute sending in turn according to the arbitration and sorting result;

[0010] Monitoring the occupation state of the time slot resource set, when the number of frames recalculated based on the actual compression effect is less than the estimated number of frames, the saved time slot resources are allocated to the target string data in the waiting queue with the largest priority aging increment through a priority adjustment mechanism.

[0011] The step of adding the compression ratio parameter to the historical compression ratio sliding window and calculating a compression ratio prediction value comprises:

[0012] An independent historical compression ratio sliding window is maintained for each content type identifier, and the historical compression ratio sliding window uses a fixed-length circular queue structure to store historical compression ratio parameters.

[0013] When a new compression ratio parameter arrives, the new compression ratio parameter is inserted into the tail of the historical compression ratio sliding window, and if the historical compression ratio sliding window is full, the compression ratio parameter at the head is automatically removed.

[0014] Based on all the compression ratio parameters in the historical compression ratio sliding window, an exponential weighted moving average algorithm is used to calculate a compression ratio prediction value.

[0015] The step of determining the time slot continuity requirement level according to the content type identifier, calculating the time slot demand amount in combination with the compression ratio prediction value, and allocating a time slot resource set on a bus time axis comprises:

[0016] The data attribute features are parsed according to the content type identifier, the time slot continuity requirement level is determined based on the data attribute features, and the corresponding time slot redundancy coefficient is obtained according to the time slot continuity requirement level.

[0017] Based on the compression ratio standard deviation of each compression ratio parameter in the historical compression ratio sliding window, when the compression ratio standard deviation exceeds a preset standard deviation threshold, a compression ratio fluctuation interval is determined based on the compression ratio prediction value and the compression ratio standard deviation.

[0018] According to the original data length of the to-be-sent string data, the lower limit value of the compression ratio fluctuation interval, and the time slot redundancy coefficient, the core time slot demand amount is calculated; according to the original data length, the upper and lower limit difference value of the compression ratio fluctuation interval, and the time slot redundancy coefficient, the standby time slot demand amount is calculated.

[0019] The time slot continuity constraint condition is determined according to the time slot continuity requirement level, an available time slot segment that meets the time slot continuity constraint condition is found on a bus time axis, the core time slot demand amount is allocated with a deterministic time slot resource in the available time slot segment, and the standby time slot demand amount is allocated with a conditional reserved time slot resource; the deterministic time slot resource and the conditional reserved time slot resource together constitute a time slot resource set.

[0020] The step of framing the encoded data into a plurality of data frames and constructing an inter-frame priority sequence for the data frames comprises:

[0021] According to the total length of the encoded data and the payload capacity of a CAN2.0 data frame, the encoded data is divided into a plurality of data frames according to a preset framing strategy;

[0022] Each data frame is assigned a frame sequence number and a frame type identifier, which distinguishes between a first frame, an intermediate frame and a last frame, and a basic priority weight of each data frame is determined based on the content type identifier and the frame type identifier;

[0023] A priority adjustment factor is set for each data frame based on the time position and resource attribute of each time slot resource in the set of time slot resources, and the resource attribute reflects the degree of certainty of the time slot resource;

[0024] The basic priority weight of each data frame is weighted with the corresponding priority adjustment factor to obtain an initial priority value of each data frame, and an inter-frame priority sequence is constructed according to the size relationship of the initial priority values.

[0025] The data frames are inserted into a sending queue, an effective priority value of each data frame is calculated based on the inter-frame priority sequence and the waiting time, and the data frames are arbitrated and sorted according to the effective priority values; under the constraint of the set of time slot resources, the step of sequentially performing sending according to the arbitrated and sorted results comprises:

[0026] The data frames are inserted into a sending queue, and the initial priority value and the current waiting time of each data frame in the sending queue are obtained;

[0027] The time slot urgency of each data frame corresponding to the time slot resource is calculated based on the time position of each time slot resource in the set of time slot resources, and the time slot urgency represents the time interval between the start time of the time slot resource and the current time;

[0028] A priority aging coefficient of each data frame is determined according to the time slot urgency, and the priority aging coefficient increases with the decrease of the time slot urgency; a priority aging increment is obtained by weighted calculation of the current waiting time and the corresponding priority aging coefficient;

[0029] The initial priority value and the priority aging increment are summed to obtain an effective priority value of each data frame; the data frames in the sending queue are arbitrated and sorted according to the effective priority values;

[0030] Under the constraint of the time slot resource set, data frames are extracted from the sending queue in turn according to the arbitration order to perform sending, and when the sending time of the data frames exceeds the time range of the corresponding time slot resource, the data frames are reinserted into the sending queue and the effective priority value is recalculated.

[0031] The step of allocating the saved time slot resource to the target string data with the largest priority aging increment in the waiting queue through the priority adjustment mechanism when the recalculated number of frames is less than the estimated number of frames includes:

[0032] When the sending of the first frame of the string data is completed, the actual compression ratio parameter of the first frame is obtained, and a compression yield deviation rate is calculated based on the compression ratio prediction value;

[0033] When the compression yield deviation rate exceeds a deviation threshold, the number of frames is recalculated based on the actual compression ratio parameter, and the time slot resource corresponding to the saved number of frames is calculated as a time window redundancy;

[0034] Each string data in the waiting queue is traversed, the matching degree of the estimated sending duration and the time window redundancy is calculated, and the string data with the largest priority aging increment and the matching degree exceeding a matching threshold is selected as the target string data;

[0035] The target string data is allocated a priority promotion increment and its effective priority value is increased, and an effective time window is set, and the priority promotion increment gradually decays to zero beyond the effective time window.

[0036] It also includes a step of dynamically adjusting the framing strategy based on bus load prediction:

[0037] The CAN bus occupancy rate is maintained by monitoring a sliding window, and after the sending of the first frame of the string data is completed, the expected transmission delay of the remaining data frames is calculated based on the CAN bus occupancy rate and the actual compression ratio parameter;

[0038] The expected transmission delay is compared with the remaining time window of the time slot resource set, and when the remaining time window is insufficient, the maximum number of frames that can be sent is recalculated and the frames are re-framed, and the priority weight of the re-framed data frames is increased based on the time window tightness;

[0039] When the remaining time window is sufficient and the number of frames is reduced by more than a preset reduction threshold, the priority weight of the remaining data frames of the current string data is reduced, and the reduction is converted into a priority transfer resource to join a global priority scheduling pool;

[0040] The string data with the highest time urgency is selected from the waiting queue, and the priority transfer resource is allocated to the string data to improve its effective priority value.

[0041] In a second aspect, the application provides a CAN 2.0 data frame real-time priority scheduling system, comprising:

[0042] A compression encoding module is configured to acquire string data to be sent, extract a content type identifier and a redundancy feature, perform adaptive compression encoding based on the redundancy feature, obtain encoded data and a compression ratio parameter, maintain a historical compression ratio sliding window corresponding to the content type identifier, add the compression ratio parameter to the historical compression ratio sliding window, and calculate a compression ratio prediction value.

[0043] A time slot allocation module is configured to determine a time slot continuity requirement level according to the content type identifier, calculate a time slot demand amount in combination with the compression ratio prediction value, and allocate a time slot resource set on a bus time axis.

[0044] A framing processing module is configured to frame the encoded data into a plurality of data frames and construct an inter-frame priority sequence for the data frames.

[0045] An arbitration sending module is configured to insert the data frames into a sending queue, calculate an effective priority value of each data frame based on the inter-frame priority sequence and a waiting time length, perform arbitration sorting according to the effective priority value, and sequentially perform sending according to the arbitration sorting result under the constraint of the time slot resource set.

[0046] A resource monitoring and scheduling module is configured to monitor an occupation state of the time slot resource set, and when a number of frames recalculated based on an actual compression effect is less than an estimated number of frames, allocate time slot resources saved through a priority adjustment mechanism to target string data with the largest priority aging increment in a waiting queue.

[0047] In a third aspect, the application provides an electronic device, comprising:

[0048] The electronic device comprises:

[0049] A processor;

[0050] A memory for storing processor-executable instructions;

[0051] The processor is configured to invoke instructions stored in the memory to perform the method described above.

[0052] In a fourth aspect, the application provides a computer readable storage medium having computer program instructions stored thereon, wherein the computer program instructions are executed by a processor to implement the method described above.

[0053] The computer readable storage medium has computer program instructions stored thereon, wherein the computer program instructions are executed by a processor to implement the method described above.

[0054] The application combines the content type identification to determine the time slot continuity requirement level, and performs resource pre-allocation based on the compression ratio prediction value, so that the real-time requirement of different types of data is ensured to be met, the effective priority value is calculated by constructing the inter-frame priority sequence and combining the waiting time length, the dynamic arbitration scheduling is realized, the starvation problem caused by long-term waiting of low priority data is avoided, and the fairness and real-time performance of system scheduling are ensured.

[0055] The application can realize dynamic recovery and secondary allocation of time slot resources by monitoring the actual occupation state of the time slot resource set, and allocating the saved time slot resources to the target data with the largest priority aging increment through the priority adjustment mechanism, thereby improving the utilization efficiency of bus resources. BRIEF DESCRIPTION OF DRAWINGS

[0056] Figure 1 A flowchart of the CAN2.0 data frame real-time priority scheduling method of the embodiment of the application is shown in

[0057] Figure 2 A flowchart of the data frame dynamic priority arbitration and sending scheduling based on time slot urgency is shown in DETAILED DESCRIPTION

[0058] To make the purpose, technical scheme and advantages of the embodiments of the application clearer, the technical scheme in the embodiments of the application will be described clearly and completely below with reference to the drawings in the embodiments of the application. Obviously, the described embodiments are only part of the embodiments of the application, rather than all the embodiments of the application. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor fall within the protection scope of the application.

[0059] The technical scheme of the application will be described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described in some embodiments.

[0060] Figure 1 A flowchart of the CAN2.0 data frame real-time priority scheduling method of the embodiment of the application is shown in Figure 1 As shown in the figure, the method comprises:

[0061] The string data to be sent is acquired, the content type identification and the redundancy feature are extracted, adaptive compression coding is performed based on the redundancy feature, and encoded data and a compression ratio parameter are obtained. The historical compression ratio sliding window corresponding to the content type identification is maintained, the compression ratio parameter is added to the historical compression ratio sliding window, and a compression ratio prediction value is calculated.

[0062] According to the content type identifier, a time slot continuity requirement level is determined, a time slot demand is calculated in combination with the compression ratio prediction value, and a time slot resource set is allocated on a bus time axis;

[0063] The encoded data is framed into a plurality of data frames, and an inter-frame priority sequence is constructed for the data frames;

[0064] The data frames are inserted into a sending queue, an effective priority value of each data frame is calculated based on the inter-frame priority sequence and a waiting time length, and arbitration sorting is performed according to the effective priority value; and under the constraint of the time slot resource set, sending is performed in sequence according to the arbitration sorting result.

[0065] The occupation state of the time slot resource set is monitored, and when the number of frames recalculated based on an actual compression effect is less than an estimated number of frames, the saved time slot resources are allocated to target string data with the largest priority aging increment in the waiting queue through a priority adjustment mechanism.

[0066] In an optional embodiment, a history compression ratio sliding window corresponding to the content type identifier is maintained, the compression ratio parameter is added to the history compression ratio sliding window, and the step of calculating the compression ratio prediction value comprises:

[0067] An independent history compression ratio sliding window is maintained for each content type identifier, and the history compression ratio sliding window adopts a fixed-length circular queue structure to store history compression ratio parameters;

[0068] When a new compression ratio parameter arrives, the new compression ratio parameter is inserted into the tail of the history compression ratio sliding window, and if the history compression ratio sliding window is full, the compression ratio parameter at the head is automatically removed;

[0069] Based on all the compression ratio parameters in the history compression ratio sliding window, an exponential weighted moving average algorithm is used to calculate the compression ratio prediction value.

[0070] An exemplary, the original string data block is received from the application layer, which carries a content type identification field, which is encoded with an 8-bit unsigned integer, with a value range of 0 to 255, where 0 to 63 identifies text data, 64 to 127 identifies binary stream data, 128 to 191 identifies mixed format data, and 192 to 255 is reserved for custom types. The extraction of the content type identification is completed by parsing the field at the fixed offset position of the data block header, without traversing the data content. The redundancy feature extraction performs a single scan on the string data, and counts the frequency of continuous repeated character sequences, the average length of repeated sequences, and the character distribution entropy value. The continuous repeated character sequence is defined as a substring with the same character at adjacent positions and a length of not less than 3, the frequency is accumulated by a counter, and the average length is obtained by dividing the total length by the number of sequences, and the result is rounded down. The character distribution entropy value is calculated based on the occurrence probability of 256 possible character values, and the probability is obtained by dividing the number of character occurrences by the total data length. When calculating the entropy value, the occurrence probability of each character is multiplied by the logarithm of the probability to the base 2, and the sum of the products of all 256 characters is added to obtain the final entropy value. The logarithm value is accurate to 4 decimal places, and the entropy value range is 0 to 8.

[0071] The adaptive compression encoding selects a compression algorithm according to the redundancy feature. When the frequency of continuous repeated character sequences exceeds 10% of the data length and the average length is greater than 5, the run-length encoding algorithm is used, which represents continuous repeated characters as a binary tuple of character value plus repetition count. The repetition count is encoded using variable length encoding, with 1 to 127 times occupying 1 byte and 128 to 16383 times occupying 2 bytes. When the character distribution entropy value is less than 4.5, static Huffman encoding is used, which pre-constructs a code table based on character frequency, assigns short code words to high-frequency characters, and assigns long code words to low-frequency characters. The code table is attached as metadata in the header of the encoded data, occupying no more than 512 bytes. When neither of the above conditions is met, a dictionary compression algorithm is used, which maintains a sliding window of length 4096, matches repeated substrings of length not less than 3, and outputs a combination of offset and length. The offset is encoded using 12 bits, and the length is encoded using 4 bits. The encoded data includes compression algorithm identification, metadata area, and compression payload, with the compression algorithm identification occupying 2 bits and located in the high bits of the first byte of the data block. The compression ratio parameter is calculated by dividing the original data length by the encoded data length, with the result accurate to 2 decimal places and a value range of 1.00 to 20.00. When compression actually increases the data length, the compression ratio is recorded as 1.00 and marked as uncompressed.

[0072] A separate history compression ratio sliding window is maintained for each content type identifier. The history compression ratio sliding window uses a fixed-length circular queue structure to store the history compression ratio parameters. The queue length is fixed at 16, and the queue is stored using a continuous memory block. Each element occupies 4 bytes, with the first 2 bytes storing the fixed-point representation of the compression ratio parameter and the last 2 bytes storing the relative value of the timestamp. The circular queue is maintained using a head pointer and a tail pointer. The head pointer points to the oldest element position, and the tail pointer points to the next writable position. Both pointers have initial values of 0 and a value range of 0 to 15. The memory space for all history compression ratio sliding windows is pre-allocated for the 256 possible content type identifiers. The corresponding history compression ratio sliding window is accessed directly using the content type identifier value as an index. The base address of each history compression ratio sliding window is calculated by multiplying the content type identifier value by 64 bytes, which occupies a total of 16384 bytes, avoiding the time uncertainty caused by dynamic allocation. The compression ratio parameter is multiplied by 100 and converted to an unsigned 16-bit integer before storage. The timestamp records the result of the modulo operation of the millisecond number relative to the system startup time on 65536. The two data items are arranged closely without padding bytes.

[0073] When a new compression ratio parameter arrives, the target history compression ratio sliding window is located according to the corresponding content type identifier. The new compression ratio parameter is written into the tail position of the history compression ratio sliding window in fixed-point format, and the timestamp is written into the last 2 bytes. The tail pointer is incremented by 1 and modulo 16. If the tail pointer is equal to the head pointer before incrementing, it indicates that the history compression ratio sliding window is full. The head pointer is incremented by 1 and modulo 16 to automatically remove the compression ratio parameter at the head of the queue, and then the above insertion operation is performed. The insertion process does not involve data movement, and only pointer updating is required to complete the circular coverage. The time complexity of a single insertion operation is constant. When the history compression ratio sliding window is not full, the head pointer remains at the initial value of 0. When the history compression ratio sliding window is full, the head pointer moves synchronously with the tail pointer, always maintaining 16 valid elements.

[0074] The compression ratio prediction value is calculated using the exponential weighted moving average algorithm, based on all compression ratio parameters in the history compression ratio sliding window. The calculation starts from the head pointer position of the history compression ratio sliding window and traverses to the position before the tail pointer. Each compression ratio parameter is assigned a weight, with the weight value being 0.9^n n , where n represents the distance of the element from the tail pointer position. The weight of the latest element is 0.9 0 =1.0, the weight of the second latest element is 0.9 1 =0.9, and the weight of the third latest element is 0.9 2=0.81, sequentially decreasing. During the traversal, each compression ratio parameter is divided by 100 from fixed-point format to restore to floating-point value, multiplied by the corresponding weight and accumulated to the weighted sum variable, while the weight is accumulated to the weight sum variable. After the traversal, the weighted sum is divided by the weight sum to obtain the weighted average value as the compression ratio prediction value, and the result is retained to 2 decimal places. When the number of elements in the historical compression ratio sliding window is less than 4, the compression ratio prediction value is directly taken as the arithmetic average of all elements in the historical compression ratio sliding window, and the exponential weighting is not applied. During the execution of the algorithm, the weight sum and the weighted sum use single-precision floating-point intermediate variables for storage, and the final result is converted to fixed-point representation to save storage space.

[0075] The application distinguishes data characteristics through content type identification and maintains independent historical compression ratio sliding windows, realizes compression ratio prediction by combining the exponential weighted moving average algorithm, can dynamically adjust the prediction value according to the time sequence change trend of the data type, improves the accuracy of time slot resource allocation, and reduces resource waste and transmission delay.

[0076] In an optional implementation, according to the content type identification, the time slot continuity requirement level is determined, and the time slot demand quantity is calculated in combination with the compression ratio prediction value, and the step of allocating a time slot resource set on a bus time axis comprises:

[0077] According to the data attribute feature obtained by analyzing the content type identification, the time slot continuity requirement level is determined, and the corresponding time slot redundancy coefficient is obtained according to the time slot continuity requirement level;

[0078] Based on the compression ratio standard deviation calculated from each compression ratio parameter in the historical compression ratio sliding window, when the compression ratio standard deviation exceeds a preset standard deviation threshold, the compression ratio fluctuation interval is determined based on the compression ratio prediction value and the compression ratio standard deviation;

[0079] According to the original data length of the to-be-sent string data, the lower limit value of the compression ratio fluctuation interval and the time slot redundancy coefficient, the core time slot demand quantity is calculated; according to the original data length, the upper and lower limit difference value of the compression ratio fluctuation interval and the time slot redundancy coefficient, the standby time slot demand quantity is calculated;

[0080] According to the time slot continuity requirement level, the time slot continuity constraint condition is determined, the available time slot segment meeting the time slot continuity constraint condition is searched on the bus time axis, the deterministic time slot resource is allocated for the core time slot demand quantity in the available time slot segment, and the conditional reserved time slot resource is allocated for the standby time slot demand quantity; the deterministic time slot resource and the conditional reserved time slot resource jointly constitute a time slot resource set.

[0081] Exemplarily, the content type identifier field is parsed to obtain data attribute characteristics, including three indicators of real-time requirement, fault tolerance capability and transmission priority. The real-time requirement is quantified by data transmission delay tolerance, with high level corresponding to delay tolerance less than 10 milliseconds, medium level corresponding to delay tolerance between 10 and 50 milliseconds, and low level corresponding to delay tolerance greater than 50 milliseconds. The fault tolerance capability is quantified by the degree of system impact after data loss or damage, with high level indicating that the system can be recovered by redundant information after data loss, medium level indicating that the system function is partially damaged but can continue to run after data loss, and low level indicating that the system function is severely damaged or stops running after data loss. The transmission priority is quantified by the competition weight of data in bus arbitration, with high level corresponding to weight value greater than or equal to 200, medium level corresponding to weight value between 100 and 199, and low level corresponding to weight value less than 100. Content type identifier 0 to 63 corresponds to text data, with real-time requirement set to low level, fault tolerance capability set to high level, and transmission priority set to medium level; content type identifier 64 to 127 corresponds to binary stream data, with real-time requirement set to high level, fault tolerance capability set to low level, and transmission priority set to high level; content type identifier 128 to 191 corresponds to mixed format data, with real-time requirement set to medium level, fault tolerance capability set to medium level, and transmission priority set to medium level. The time slot continuity requirement level is determined according to the combination of real-time requirement and fault tolerance capability, with high level of real-time requirement and low level of fault tolerance capability, the time slot continuity requirement level is strict continuity, requiring the allocated time slot resources to be continuous without interruption on the bus time axis; when the real-time requirement is medium level, the time slot continuity requirement level is preferential continuity, allowing the time slot resources to have a gap of no more than 2 time slot units; when the real-time requirement is low level, the time slot continuity requirement level is loose continuity, allowing the time slot resources to have a gap of no more than 5 time slot units. The time slot redundancy coefficient is obtained according to the time slot continuity requirement level, with strict continuity corresponding to a time slot redundancy coefficient of 1.2, preferential continuity corresponding to a time slot redundancy coefficient of 1.15, and loose continuity corresponding to a time slot redundancy coefficient of 1.1. The time slot redundancy coefficient is used to reserve additional time slot resources to cope with bus load fluctuations when calculating the time slot demand.

[0082] The compression ratio standard deviation is calculated based on all compression ratio parameters in the historical compression ratio sliding window, starting from the head pointer position of the historical compression ratio sliding window to the position before the tail pointer, extracting each compression ratio parameter and calculating the arithmetic mean, the difference between each compression ratio parameter and the arithmetic mean is squared, the sum of all square values is divided by the number of elements to obtain the variance, the square root of the variance is obtained to obtain the compression ratio standard deviation, and the result is retained to two decimal places. The preset standard deviation threshold is set to 0.15, when the compression ratio standard deviation exceeds 0.15, it indicates that the compression effect fluctuates greatly, and the compression ratio fluctuation interval needs to be determined to improve the robustness of time slot allocation. The lower limit value of the compression ratio fluctuation interval = compression ratio prediction value - 2 x compression ratio standard deviation, the lower limit value cannot be less than 1.00, when the calculation result is less than 1.00, take 1.00. The upper limit value of the compression ratio fluctuation interval is calculated by adding twice the compression ratio standard deviation to the compression ratio prediction value, and the upper limit value cannot be greater than 20.00, when the calculation result is greater than 20.00, take 20.00. When the compression ratio standard deviation does not exceed 0.15, the lower limit value and the upper limit value of the compression ratio fluctuation interval are both set to the compression ratio prediction value, indicating that the compression effect is stable and no fluctuation space needs to be reserved.

[0083] The core time slot demand is calculated according to the original data length of the to-be-sent string data, the lower limit value of the compression ratio fluctuation interval, and the time slot redundancy coefficient. The original data length is divided by the lower limit value of the compression ratio fluctuation interval to obtain the expected encoded data length, and the expected encoded data length is divided by the payload capacity of 8 bytes of the CAN2.0 data frame to obtain the expected framing number, which is rounded up. The expected framing number is multiplied by the time slot redundancy coefficient to obtain the core time slot demand, which is rounded up. The core time slot demand represents the number of time slot resources required under the most conservative compression effect estimation. The standby time slot demand is calculated according to the original data length, the difference between the upper and lower limits of the compression ratio fluctuation interval, and the time slot redundancy coefficient. The original data length is divided by the upper limit value of the compression ratio fluctuation interval to obtain the encoded data length under the optimal condition, which is divided by 8 bytes and rounded up to obtain the optimal framing number. The core time slot demand is subtracted by the optimal framing number to obtain the framing number difference, and the framing number difference is multiplied by the time slot redundancy coefficient to obtain the standby time slot demand, which is rounded up. The standby time slot demand represents the number of time slot resources that can be saved when the compression effect is better than expected, which is used for conditional reservation to improve resource utilization.

[0084] The time slot continuity constraint condition is determined according to a time slot continuity requirement level, the strict continuity requirement is that the time slot resources in the available time slot segment must be continuous without interruption, and the time interval of any two adjacent time slots is not more than a standard time length of 1 time slot unit. The preferential continuity requirement allows not more than 1 discontinuity point in the available time slot segment, and the time interval at the discontinuity point is not more than 2 time slot units. The loose continuity requirement allows not more than 3 discontinuity points in the available time slot segment, and the time interval at each discontinuity point is not more than 5 time slot units. The bus time axis is discretized in time slot units of 1 millisecond, and a time slot occupation bitmap with a length of 1000 is maintained, and each bit represents the occupation state of the corresponding time slot, 0 represents idle, and 1 represents occupation. When searching for an available time slot segment that meets the time slot continuity constraint condition, the time slot occupation bitmap is scanned from the time slot position corresponding to the current time, the length of the continuous idle time slot, and the number and interval size of the discontinuity points are counted, and when an available time slot segment that meets the constraint condition and has a length not less than the sum of the core time slot requirement and the standby time slot requirement is found, the scanning is stopped and the start time slot position and the end time slot position of the available time slot segment are recorded.

[0085] The deterministic time slot resource is allocated for the core time slot requirement in the available time slot segment, the core time slot requirement is continuously allocated from the start time slot position of the available time slot segment, the corresponding bit in the time slot occupation bitmap is set to 1, and the time stamp, data frame identifier and resource type identifier of each time slot are recorded in the time slot resource table. The resource type identifier is set to deterministic, indicating that the time slot resource has been locked and cannot be preempted by other data frames. The conditional reservation time slot resource is allocated immediately after the deterministic time slot resource, and the standby time slot requirement is allocated from the end position of the core time slot requirement. The corresponding bit in the time slot occupation bitmap is set to 2, indicating that the time slot is in a reserved state. The time stamp, data frame identifier and resource type identifier are recorded in the time slot resource table, and the resource type identifier is set to conditional reservation, indicating that the time slot resource can be released to other high-priority data frames when the actual compression effect is better than expected. The start time of the time slot resource set is the time stamp of the first time slot of the deterministic time slot resource, the end time is the time stamp of the last time slot of the conditional reservation time slot resource, and the total length of the time slot resource set is the sum of the core time slot requirement and the standby time slot requirement.

[0086] The application realizes fine allocation of time slot resources through the double-layer mechanism of time slot continuity requirement level and compression ratio fluctuation interval, the deterministic time slot resource guarantees the reliability of data transmission, the conditional reservation time slot resource improves the utilization rate of bus resources, and reduces resource fragmentation and transmission delay.

[0087] In an optional implementation, the coded data is framed into multiple data frames, and the step of constructing an inter-frame priority sequence for the data frames includes:

[0088] According to the total length of the encoded data and the payload capacity of the CAN2.0 data frame, the encoded data is divided into multiple data frames according to a preset framing strategy;

[0089] A frame sequence number and a frame type identifier are assigned to each data frame, the frame type identifier distinguishes a first frame, an intermediate frame and a last frame, and a basic priority weight of each data frame is determined based on the content type identifier and the frame type identifier;

[0090] A priority adjustment factor is set for each data frame based on the time position and resource attribute of each time slot resource in the set of time slot resources, and the resource attribute reflects the degree of certainty of the time slot resource;

[0091] The basic priority weight of each data frame is weighted with the corresponding priority adjustment factor to obtain an initial priority value of each data frame, and an inter-frame priority sequence is constructed according to the size relationship of the initial priority values.

[0092] For example, the total number of bytes of the encoded data is obtained as the length of the data to be framed, and the payload capacity of the CAN2.0 data frame is fixed at 8 bytes. The length of the data to be framed is divided by 8 bytes to obtain the theoretical number of frames, and when the division result has a decimal part, the integer part is taken to ensure that all data is completely loaded. The framing strategy adopts a sequential division method, starting from the first byte of the encoded data and dividing by a fixed step of 8 bytes, and each 8 bytes forms a payload part of a data frame. The payload length of the last data frame may be less than 8 bytes, in which case the payload tail is filled with 0xFF padding bytes until the length reaches 8 bytes, and the actual data byte number is recorded in the frame header part of the data frame. A globally unique frame sequence number is assigned to each data frame during the framing process, the frame sequence number starts from 0 and increments, the value range is 0 to the theoretical number of frames minus 1, the frame sequence number occupies 2 bytes of storage space and is embedded in the frame header part of the data frame. The frame type identifier field occupies 1 byte, the value includes 0x01 indicating the first frame, 0x02 indicating the intermediate frame, and 0x03 indicating the last frame. The first frame corresponds to the data frame with frame sequence number 0, the last frame corresponds to the data frame with frame sequence number equal to the theoretical number of frames minus 1, and the remaining data frames are all identified as intermediate frames.

[0093] The basic priority weight is determined according to a combination of a content type identifier and a frame type identifier, the content type identifier ranges from 0 to 255, and the frame type identifier takes a value of a first frame, a middle frame or a last frame. A basic weight value corresponding to the content type identifier is obtained by table lookup, the content type identifier 0 to 63 corresponds to the basic weight value 100, the content type identifier 64 to 127 corresponds to the basic weight value 200, the content type identifier 128 to 191 corresponds to the basic weight value 150, and the content type identifier 192 to 255 corresponds to the basic weight value 120. A weight correction coefficient corresponding to the frame type identifier, the correction coefficient of the first frame is 1.3, the correction coefficient of the middle frame is 1.0, and the correction coefficient of the last frame is 1.2. The basic priority weight of each data frame is calculated by multiplying the basic weight value corresponding to the content type identifier by the correction coefficient corresponding to the frame type identifier, and the calculation result is rounded to an integer part, and the decimal part is processed according to the rounding rule.

[0094] The priority adjustment factor is set based on the time position and resource attribute of each time slot resource in the time slot resource set, the time slot resource set includes two types of deterministic time slot resources and conditionally reserved time slot resources, and the resource attribute is distinguished by a resource type identifier field. The resource attribute value of the deterministic time slot resource is set to 1.0, and the resource attribute value of the conditionally reserved time slot resource is set to 0.8. The time position is represented by the relative position index of the time slot resource in the time slot resource set, and the index value starts from 0 and increases, and the smaller the index value, the closer the time slot resource is to the starting position of the time slot resource set. When calculating the priority adjustment factor, first, the time slot resource position that should be occupied by the data frame is determined according to the frame sequence number of the data frame, and the frame sequence number and the time slot resource position index have a one-to-one correspondence, and the data frame with the frame sequence number n corresponds to the time slot resource position index n. The resource attribute value of the time slot resource is obtained, and the time position weight is calculated, the time position weight is obtained by dividing the total length of the time slot resource set by the total length of the time slot resource set minus the time slot resource position index, and the result is kept to two decimal places. The priority adjustment factor is calculated by multiplying the resource attribute value by the time position weight and then multiplying by a fixed coefficient 50, the fixed coefficient 50 is used to amplify the adjustment factor value to a magnitude comparable to the basic priority weight, and the calculation result is rounded to an integer part.

[0095] The initial priority value is calculated by weighting the base priority weight and the priority adjustment factor, the weighting calculation adopts linear addition mode, the base priority weight of each data frame and the corresponding priority adjustment factor are directly added to obtain the initial priority value, the initial priority value is a positive integer and the larger the value is, the higher the priority is. The inter-frame priority sequence is constructed according to the size relationship of the initial priority value, all data frames are arranged in descending order according to the initial priority value from large to small, and the data frames with the same initial priority value are arranged in ascending order according to the frame serial number from small to large to ensure uniqueness. The inter-frame priority sequence is stored in the form of a linear table, each element contains five attributes of the frame serial number, the frame type identifier, the base priority weight, the priority adjustment factor and the initial priority value of the data frame, and the element order of the linear table is the priority order of the data frame in the bus transmission.

[0096] The application realizes fine allocation of data frame priority by the dual weight mechanism of content type identifier and frame type identifier combined with dynamic adjustment of time slot resource attribute, ensures that the key frame type and high priority content are transmitted preferentially, and improves the bus resource utilization efficiency and data transmission reliability.

[0097] In an optional implementation, the data frame is inserted into a sending queue, an effective priority value of each data frame is calculated based on the inter-frame priority sequence and a waiting time length, and arbitration sorting is performed according to the effective priority value; under the constraint of the time slot resource set, the step of sequentially performing transmission according to the arbitration sorting result comprises the following steps.

[0098] The data frame is inserted into a sending queue, and the initial priority value and the current waiting time length of each data frame in the sending queue are obtained;

[0099] Based on the time position of each time slot resource in the time slot resource set, the time slot urgency of the time slot resource corresponding to each data frame is calculated, and the time slot urgency represents the time interval between the starting time of the time slot resource and the current time;

[0100] The priority aging coefficient of each data frame is determined according to the time slot urgency, the priority aging coefficient increases with the decrease of the time slot urgency; and the current waiting time length and the corresponding priority aging coefficient are weighted to obtain a priority aging increment;

[0101] The initial priority value and the priority aging increment are summed to obtain the effective priority value of each data frame; and the data frames in the sending queue are arbitrated and sorted according to the effective priority value;

[0102] Under the constraint of the set of time slot resources, data frames are extracted from the sending queue in turn according to the arbitration sorting result to perform sending, and when the sending time of a data frame exceeds the time range of the corresponding time slot resource, the data frame is reinserted into the sending queue and the effective priority value is recalculated.

[0103] In combination Figure 2 The data frame dynamic priority arbitration and sending scheduling flowchart based on time slot urgency is described. Exemplarily, a priority queue structure is used when data frames are inserted into the sending queue. The queue node includes five fields of data frame identification, frame serial number, initial priority value, insertion time stamp, and time slot resource binding information. The data frame identification uses a 4-byte unsigned integer, which is generated by splicing the high 8 bits of the content type identification and the low 24 bits of the frame serial number, to ensure global uniqueness. The insertion time stamp records the system time when the data frame enters the sending queue, which is stored in a 64-bit unsigned integer in milliseconds, and the time stamp is derived from the system monotonic clock to avoid the influence of time rollback. The time slot resource binding information includes the start time and end time of the time slot resource allocated to the data frame and the resource type identification. The start time and end time are recorded in milliseconds, and the resource type identification distinguishes between deterministic time slot resources and conditional reserved time slot resources. The sending queue is implemented using a heap structure, and the top element of the heap is the data frame with the highest current effective priority value. The time complexity of the insertion operation is logarithmic, and the extraction operation is also logarithmic. The upper limit of the queue capacity is set to 256 nodes. When the queue is full and a new data frame arrives, the priority of the new data frame and the node with the lowest effective priority value in the queue is compared. If the new data frame has a higher priority, the node with the lowest priority is replaced. Otherwise, the congestion control mechanism is triggered to delay insertion.

[0104] The initial priority value of each data frame in the sending queue is directly read from the initial priority value field of the queue node. This field has been assigned a value when the inter-frame priority sequence is constructed and remains unchanged. The current waiting time is calculated by subtracting the insertion time stamp of the data frame from the current system time, and the result is in milliseconds. The current system time is also derived from the system monotonic clock. The current waiting time is a dynamic value that needs to be recalculated in each arbitration sorting period of the sending queue. The arbitration sorting period is fixed at 5 milliseconds, and the arbitration sorting task is triggered by a timer.

[0105] The time slot urgency is calculated based on the time position of the time slot resource, which is represented by the start time of the time slot resource. The time slot urgency is defined as the time interval between the start time of the time slot resource and the current time, which is calculated by subtracting the current time from the start time of the time slot resource, and the result is in milliseconds. When the start time of the time slot resource is later than the current time, the time slot urgency is positive, and the larger the value, the farther the time slot resource is from the current time, and the lower the urgency. When the start time of the time slot resource is earlier than or equal to the current time, the time slot urgency is 0 or negative, indicating that the time slot resource has entered the available window or has expired, at which time the data frame should immediately participate in arbitration or reassign the time slot resource.

[0106] The priority aging coefficient is determined according to the time slot urgency, and the correspondence between the time slot urgency and the priority aging coefficient is established by a segmented mapping method. When the time slot urgency is less than or equal to 0 milliseconds, the priority aging coefficient is set to 3.0, indicating that the time slot resource has entered the available window, and the data frame needs to maximize the priority to avoid missing the time slot. When the time slot urgency is between 1 and 10 milliseconds, the priority aging coefficient is set to 2.5, indicating that the time slot resource is about to arrive, and the priority of the data frame needs to be greatly improved. When the time slot urgency is between 11 and 50 milliseconds, the priority aging coefficient is set to 2.0, indicating that the time slot resource still has a certain amount, and the priority improvement amplitude is moderate. When the time slot urgency is between 51 and 200 milliseconds, the priority aging coefficient is set to 1.5, indicating that the time slot resource is far away, and the priority improvement amplitude is small. When the time slot urgency is greater than 200 milliseconds, the priority aging coefficient is set to 1.0, indicating that the time slot resource is abundant, and the current waiting time has a standard proportion on the priority. The priority aging increment is calculated by multiplying the current waiting time by the priority aging coefficient and then dividing by 100, and the operation of dividing by 100 is used to normalize the time unit from milliseconds to a magnitude comparable to the initial priority value, and the calculation result is rounded to the integer part, and the decimal part is discarded.

[0107] The effective priority value is calculated by summing the initial priority value and the priority aging increment, and the sum is calculated by integer addition operation, and the effective priority value is a positive integer and the larger the value, the stronger the data frame's competitiveness in the sending queue. The arbitration sorting arranges the data frames in the sending queue in descending order according to the effective priority value, and the data frames with the same effective priority value are arranged in ascending order according to the insertion time stamp from small to large, ensuring that the data frames with longer waiting time are sent first. After the arbitration sorting is completed, the top element of the heap structure is the current data frame to be sent, and the heap adjustment operation ensures that the heap property is valid after each effective priority value update.

[0108] When the data frame is extracted from the top of the stack to perform sending according to the arbitration order, the relationship between the start time of the time slot resource bound by the data frame and the current time is checked. When the current time is between the start time and the end time of the time slot resource, the data frame is immediately sent through the CAN bus sending interface, the sending register of the hardware controller is called by the sending interface, the identifier, the payload and the control field of the data frame are written into the register, and the sending operation is triggered. After the sending is successful, the data frame node is deleted from the sending queue, the queue resource is released, and the occupation state of the corresponding time slot in the time slot occupation bitmap is updated to be used. When the sending time of the data frame exceeds the end time of the corresponding time slot resource, it is determined that the time slot resource is expired, and the data frame cannot be sent in the pre-allocated time slot. At this time, the data frame is reinserted into the sending queue, the insertion time timestamp is updated to the current time when the data frame is reinserted, the time slot resource re-allocation process is triggered, new time slot resources are allocated for the data frame on the bus time axis, and the start time and the end time in the time slot resource binding information are updated. When the effective priority value is recalculated, the initial priority value remains unchanged, the current waiting time is recalculated from the reinsertion time, the time slot urgency is calculated based on the start time of the newly allocated time slot resource, and the priority aging coefficient and the priority aging increment are re-determined according to the above rules.

[0109] The application realizes adaptive priority adjustment of the data frame under time slot constraint through the dynamic linkage mechanism of the time slot urgency and the priority aging coefficient, ensures that the data frame that will arrive soon obtains a higher competitive priority, and effectively reduces the waste of time slot resources and the sending delay of the data frame.

[0110] In an optional embodiment, the occupation state of the time slot resource set is monitored, and when the number of frames recalculated based on the actual compression effect is less than the estimated number of frames, the step of allocating the saved time slot resources to the target string data with the largest priority aging increment in the waiting queue through the priority adjustment mechanism comprises the following steps:

[0111] When the first frame of the string data is sent, the actual compression ratio parameter of the first frame is obtained, and the compression yield deviation rate is calculated based on the compression ratio prediction value;

[0112] When the compression yield deviation rate exceeds the deviation threshold, the number of frames is recalculated based on the actual compression ratio parameter, and the time slot resources corresponding to the saved number of frames are taken as the time window redundancy;

[0113] Each string data in the waiting queue is traversed, the matching degree of the estimated sending time and the time window redundancy is calculated, and the string data with the matching degree exceeding the matching threshold and the largest priority aging increment is selected as the target string data;

[0114] A priority promotion increment is assigned to the target string data and its effective priority value is increased; an effective time window is set, and the priority promotion increment gradually decays to zero beyond the effective time window.

[0115] For example, the occupation state of the time slot resource set is monitored by a time slot occupation bitmap, which is stored in a bit array structure, and each bit corresponds to a time slot resource unit. A bit value of 1 indicates that the time slot is occupied, and a bit value of 0 indicates that the time slot is idle and can be allocated. The length of the time slot occupation bitmap is determined according to the maximum number of time slots in the communication period, and is configured by default as 1024 bits, corresponding to 1024 time slot resource units. The time slot occupation bitmap updates the occupation state when the string data is allocated time slot resources, and updates the release state after the data frame is sent. The state consistency under concurrent access is ensured by atomic operation. The monitoring module scans the time slot occupation bitmap at a period of 2 milliseconds, counts the number and location distribution of idle time slots, and stores the statistical results in the time slot resource state table for resource allocation decision-making.

[0116] After the first frame of the string data is sent, the actual compression ratio parameter is defined as the ratio of the number of payload bytes after compression to the number of original bytes before compression. The number of payload bytes after compression is read from the data length field of the sent CAN frame, and the number of original bytes before compression is obtained from the metadata record of the string data. The actual compression ratio parameter is calculated using fixed-point number operation, and the ratio is multiplied by 1000 and converted to an integer for storage, with a precision of one thousandth and a value range of 1 to 1000. The smaller the value, the better the compression effect. The compression ratio prediction value is calculated when the string data is framed and estimated and stored in the metadata structure of the string data. The prediction value is also represented by a fixed-point number with a precision of one thousandth. The compression yield deviation rate is calculated by subtracting the actual compression ratio parameter from the compression ratio prediction value and then dividing by the compression ratio prediction value. The result is multiplied by 100 to convert it to a percentage and stored as a signed integer. A positive compression yield deviation rate indicates that the actual compression effect is better than the prediction, and a negative compression yield deviation rate indicates that the actual compression effect is worse than the prediction. The absolute value reflects the degree of deviation. The deviation threshold is set to 15, which triggers the recalculation process when the absolute value of the compression yield deviation rate exceeds 15 percentage points. The adjustable range of the deviation threshold is 10 to 30, which is adjusted according to the content characteristics of the string data and the stability of the compression algorithm. For scenes with large fluctuations in compression effect, the threshold can be appropriately increased to avoid frequent triggering.

[0117] When the compression yield deviation rate exceeds the deviation threshold, the frame number is recalculated based on the actual compression ratio parameter. The same calculation logic as the frame estimation is used in the recalculation. The total byte length of the string data is multiplied by the actual compression ratio parameter to obtain the total byte length after compression. The total byte length after compression is divided by the maximum load byte number of a single frame to obtain the frame number. The division operation uses the upward rounding strategy to ensure that all data is covered. The maximum load byte number of a single frame is determined according to the CAN frame format. The maximum load of a standard CAN frame is 8 bytes, and the maximum load of a CAN FD frame is 64 bytes. The recalculated frame number is compared with the estimated frame number. When the recalculated frame number is less than the estimated frame number, the frame saving amount is generated. The frame saving amount is equal to the estimated frame number minus the recalculated frame number. The time slot resources corresponding to the saved frame number are calculated by multiplying the frame saving amount by the single frame time slot occupation time. The single frame time slot occupation time includes the frame transmission time and the interframe interval. The single frame time slot occupation time of a standard CAN frame is set to 0.3 milliseconds at a rate of 500 kilobits per second, and the single frame time slot occupation time of a CAN FD frame is set to 0.8 milliseconds. The calculated time slot resources are used as the time window redundancy, which is stored in milliseconds. This redundancy can be used for the priority scheduling of other string data in the waiting queue.

[0118] The waiting queue stores the string data which has completed compression and framing but has not obtained time slot resource allocation, the queue is implemented by using a linked list structure, and a node contains a string data identifier, an estimated sending duration, a priority aging increment, an insertion time, and the like. When traversing the waiting queue, each node is accessed in turn from the head node, and the matching degree of the estimated sending duration and the time window redundancy of each string data is calculated. The estimated sending duration is calculated by multiplying the estimated number of frames of the string data by the single frame time slot occupancy duration, and is stored in milliseconds. The matching degree is defined as the difference between the estimated sending duration and the time window redundancy, and is calculated by subtracting the estimated sending duration from the time window redundancy. A positive result indicates that the time window redundancy is sufficient to accommodate the string data, and a negative result indicates that the time window redundancy is insufficient. After the matching degree is calculated, it is compared with a matching threshold. The matching threshold is set to -0.2 milliseconds, that is, the estimated sending duration is allowed to exceed the time window redundancy by 0.2 milliseconds or less, so as to improve the utilization efficiency of time slot resources. The adjustable range of the matching threshold is -0.5 milliseconds to 0 milliseconds, and is adjusted according to the strictness of time slot resource allocation. The string data whose matching degree exceeds the matching threshold constitutes a candidate set, and the string data with the largest priority aging increment in the candidate set is selected as the target string data. The priority aging increment is read from the priority aging increment field of the string data node. This field records the priority increment value of the string data due to the waiting duration accumulation, and the calculation method is consistent with the priority aging increment calculation of the data frame. When there are multiple string data with the same maximum priority aging increment in the candidate set, the string data with the earliest insertion time is selected as the target string data.

[0119] When the priority promotion increment is assigned to the target string data, the value of the priority promotion increment is equal to the saved frame saving quantity multiplied by 10, and the multiplication by 10 is used to convert the frame saving quantity into a magnitude comparable to the priority value. The priority promotion increment is a positive integer, and the value range is 10 to 200. When the saved frame saving quantity exceeds 20, the upper limit of the priority promotion increment is locked at 200 to avoid excessive expansion of the priority value. After the priority promotion increment is assigned, the increment value is added to the valid priority value field of the target string data. The valid priority value field is stored in the string data node, and the initial value is the sum of the initial priority value of the string data and the priority aging increment. The addition operation uses an atomic addition instruction to ensure concurrent safety. The valid time window is set as the time window redundancy plus a 5 ms buffer margin. The valid time window is counted from the time when the priority promotion increment is assigned, and the window start time is recorded by a timer. When the valid time window is exceeded, the priority promotion increment gradually decays to zero. The decay strategy adopts a linear decay manner, and the decay rate is 5% of the initial priority promotion increment per millisecond. The decay calculation is obtained by subtracting the window start time from the current time to obtain the elapsed time. The elapsed time is multiplied by the decay rate to obtain the cumulative decay amount. The cumulative decay amount is deducted from the initial priority promotion increment to obtain the current priority promotion increment. When the cumulative decay amount is greater than or equal to the initial priority promotion increment, the current priority promotion increment is zero, and the valid priority value of the target string data reverts to the state before the priority promotion increment is assigned. The decay calculation is triggered by a timing task with a period of 1 ms. The timing task traverses all string data holding the priority promotion increment and updates the valid priority value thereof.

[0120] The application significantly improves the time slot resource utilization rate and reduces the waiting time delay of high-priority data by real-time monitoring of the actual compression effect and the prediction deviation, dynamically recycling the saved time slot resources, and accurately allocating the time slot resources to string data with high matching degree and long waiting time.

[0121] In an optional embodiment, the method further comprises a step of dynamically adjusting the frame saving strategy based on bus load prediction:

[0122] A CAN bus occupancy rate is maintained by monitoring a sliding window. When the first frame of the string data is sent, an expected transmission delay of the remaining data frames is calculated based on the CAN bus occupancy rate and the actual compression ratio parameter.

[0123] The expected transmission delay is compared with the remaining time window of the time slot resource set. When the remaining time window is insufficient, the maximum number of transmittable frames is recalculated, and the frames are reframed. The priority weight of the reframed data frames is increased based on the time window tightness.

[0124] When the remaining time window is sufficient and the number of reduced frames exceeds the preset reduction threshold, the priority weight of the remaining data frame of the current string data is reduced, and the reduction is converted into a priority transfer resource to join the global priority scheduling pool;

[0125] The string data with the highest time urgency is selected from the waiting queue, and the priority transfer resource is allocated to the string data to improve the effective priority value thereof.

[0126] Exemplarily, the bus load monitoring sliding window is implemented in a circular buffer structure with a fixed length, and the buffer length is set to 100 sampling points, each of which records the occupation time of the CAN bus in a 1-millisecond period. The sampling point data is obtained through a hardware counter of the bus controller, and the hardware counter accumulates the count value when the bus is busy. The count value is read once per millisecond and written to the current position of the sliding window, and after writing, the counter is cleared and starts counting again. The write pointer of the sliding window is incremented in a circular manner, and when the pointer reaches the end of the buffer, it is wrapped back to the start position to overwrite the oldest sampling point. The CAN bus occupancy rate is calculated by dividing the sum of the occupation time of all sampling points in the sliding window by the total time covered by the sliding window. The total time is equal to the number of sampling points multiplied by the sampling period, i.e. 100 milliseconds. The sum of the occupation time is accumulated point by point using an accumulator, and the result is divided by 100 to obtain the average occupancy rate. The result is expressed in thousandths and stored as a 16-bit unsigned integer, with a value range of 0 to 1000. A value of 1000 indicates that the bus occupancy rate is 100%. The sliding window statistical calculation is triggered at a period of 10 milliseconds, and the sliding window data is read and the occupancy rate value is updated through a timing task. The occupancy rate value is stored in a global shared variable for subsequent calculation.

[0127] The first frame of the string data is sent, and the remaining data frame expected transmission delay calculation process is triggered. The number of remaining data frames is obtained by subtracting 1 from the recalculated number of frames, and the subtraction operation excludes the first frame that has been sent. The single frame transmission delay includes frame bit time and bus contention delay. The frame bit time is calculated according to the number of bits of the CAN frame and the bus baud rate. A standard CAN frame includes an identifier, a control field, a data field, a CRC field, a response field, and an end of frame field. At a baud rate of 500 kbps, the single frame bit time is 0.22 ms. When the CAN FD frame uses a data segment rate of 2 Mbps, the single frame bit time is 0.15 ms. The bus contention delay is calculated by the CAN bus occupancy rate and an empirical coefficient. The empirical coefficient is set to 0.5. The contention delay is equal to the single frame bit time multiplied by the CAN bus occupancy rate and then multiplied by the empirical coefficient. The occupancy rate is calculated using the thousandth percentage value and then normalized by dividing by 1000. The single frame transmission delay is equal to the frame bit time plus the contention delay. The expected transmission delay of the remaining data frames is equal to the single frame transmission delay multiplied by the number of remaining data frames. The result is stored in milliseconds with a precision of 0.01 ms. Fixed-point arithmetic is used to maintain calculation accuracy.

[0128] The remaining time window is calculated by subtracting the current time from the end time of the time slot resource bound to the string data. The end time of the time slot resource is recorded in the metadata structure of the string data, and the current time is read from the system monotonic clock. The remaining time window is stored in milliseconds. The comparison between the expected transmission delay and the remaining time window is achieved by subtraction. When the result of the remaining time window minus the expected transmission delay is less than 0.5 ms, it is determined that the remaining time window is insufficient. 0.5 ms is a safety margin to avoid transmission failure caused by timing boundary conditions. When the remaining time window is insufficient, the re-framing process is triggered. The maximum number of frames that can be sent is calculated by dividing the remaining time window by the single frame transmission delay. The division uses a down rounding strategy to ensure that all frames can be sent within the time window. When re-framing, the remaining data is re-divided according to the maximum number of frames that can be sent. The division strategy ensures that the number of bytes in each frame is evenly distributed to avoid the last frame having too few bytes, which would reduce transmission efficiency. The data frames generated by re-framing replace the original remaining data frames. The data bytes that cannot be accommodated are marked as data to be retransmitted and trigger the time slot resource re-application process. The time window tightness is defined as the ratio of the expected transmission delay to the remaining time window. It is calculated by dividing the expected transmission delay by the remaining time window. The result is multiplied by 100 to convert it to a percentage. The larger the tightness value, the tighter the time window. The priority weight increase is calculated by multiplying the time window tightness by a tightness coefficient. The tightness coefficient is set to 0.3. The increase value ranges from 0 to 30. When the calculation result exceeds 30, the upper limit is locked at 30. After re-framing, the priority weight of the data frame is increased by the original priority plus the increase. The priority weight field is stored in the metadata structure of the data frame, and the increase is calculated by an atomic addition instruction.

[0129] The condition for determining sufficient remaining time window is that the result of subtracting the expected transmission delay from the remaining time window is greater than or equal to 2 milliseconds. 2 milliseconds is the sufficient margin threshold, and this threshold is adjustable within a range of 1 to 5 milliseconds. The reduction in the number of frames is calculated by subtracting the recalculated number of frames from the estimated number of frames. This reduction amount is determined when recalculating the number of frames based on the actual compression ratio parameters. The preset reduction threshold is set to 2, meaning that when the reduction in the number of frames is greater than or equal to 2, the priority weight reduction process is triggered. When reducing the priority weight of the remaining data frames of the current string data, the reduction amount is calculated using a segmented strategy: the reduction amount is 10 when the reduction in the number of frames is 2 to 4, 15 when the reduction is 5 to 7, and 20 when the reduction is greater than or equal to 8. The priority weight reduction is achieved by subtracting the reduction amount from the priority weight field of the remaining data frames. The subtraction operation ensures that the priority weight is not lower than 50% of the initial priority. When the calculation result is lower than this lower limit, the priority weight is locked at 50% of the initial priority. When reducing the amount of resources and converting it into priority-granted resources, a 1:1 conversion ratio is used, meaning the reduced amount is directly used as the amount of resources to be granted as priority. The global priority scheduling pool is implemented using a resource pool data structure. The pool maintains the total amount of allocatable priority-granted resources. The total amount of resources is increased by adding new resources and subtracted from already allocated resources through subtraction. Access to the resource pool is protected by mutex locks to avoid concurrent conflicts.

[0130] The time urgency of the string data in the waiting queue is calculated by the time difference between the expected sending time of the string data and the current time, the expected sending time being recorded in the metadata of the string data and being set by an upper application when generating the string data. The time difference is calculated by subtracting the current time from the expected sending time, and a positive result indicates that the expected sending time has not arrived, and the smaller the value is, the more urgent the time is. A negative result or 0 indicates that the expected sending time has been exceeded, and the time urgency reaches the highest level. When selecting the string data with the highest time urgency, the waiting queue is traversed, the time difference of each string data is compared, the string data with the smallest time difference is selected, and when there are multiple string data with the same time difference, the string data with the earliest insertion time is selected. The allocation of priority resources adopts a full allocation strategy, and the available resource amount in the global priority scheduling pool is allocated to the selected string data, and the allocation operation is implemented by adding the resource amount to the effective priority value field of the string data. After the addition is completed, the resource amount of the global priority scheduling pool is cleared. After the allocation of the priority resources, the effective priority value of the string data is improved, and the competition ability is enhanced in the subsequent arbitration sorting, and the probability of obtaining the time slot resource allocation is improved. The effective period of the priority resources is set to 50 milliseconds, and the effective period is counted from the time of resource allocation. If the string data has not obtained the time slot resource after the effective period, the allocated priority resources are deducted from the effective priority value, and the resources are recycled to the global priority scheduling pool for use by other string data.

[0131] The application dynamically adjusts the frame division strategy and the priority weight through the joint monitoring of the bus load and the actual compression effect, guarantees the transmission of key data when the time window is tight, and improves the scheduling priority of urgent data through the priority transfer mechanism when the time window is sufficient, so that the dual goals of efficient resource utilization and time delay optimization are realized.

[0132] In a second aspect of the embodiment of the application, a CAN2.0 data frame real-time priority scheduling system is provided, comprising:

[0133] The compression encoding module is configured to obtain string data to be sent, extract a content type identifier and a redundancy feature, perform adaptive compression encoding based on the redundancy feature, obtain encoded data and a compression ratio parameter, maintain a historical compression ratio sliding window corresponding to the content type identifier, add the compression ratio parameter to the historical compression ratio sliding window, and calculate a compression ratio prediction value.

[0134] The time slot allocation module is configured to determine a time slot continuity requirement level according to the content type identifier, calculate a time slot demand amount in combination with the compression ratio prediction value, and allocate a time slot resource set on a bus time axis.

[0135] The frame processing module is configured to divide the encoded data into a plurality of data frames, and construct an inter-frame priority sequence for the data frames.

[0136] The arbitration sending module is configured to insert the data frames into a sending queue, calculate an effective priority value of each data frame based on the inter-frame priority sequence and the waiting time length, and perform arbitration sorting according to the effective priority value; and under the constraint of the time slot resource set, sequentially perform sending according to the arbitration sorting result.

[0137] The resource monitoring and scheduling module is configured to monitor the occupation state of the time slot resource set, and when the number of frames recalculated based on the actual compression effect is less than the estimated number of frames, allocate the saved time slot resources to a target string data with the largest priority aging increment in the waiting queue through a priority adjustment mechanism.

[0138] In a third aspect, an electronic device is provided, comprising:

[0139] a processor;

[0140] a memory for storing processor-executable instructions;

[0141] The processor is configured to invoke the instructions stored in the memory to execute the method described above.

[0142] In a fourth aspect, a computer-readable storage medium is provided, which stores computer program instructions, and the computer program instructions are executed by a processor to implement the method described above.

[0143] The present application can be a method, device, system and / or computer program product. The computer program product can include a computer readable storage medium having computer readable program instructions stored therein, which are used to perform various aspects of the present application.

[0144] Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present application, and not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: it can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A real-time priority scheduling method for CAN2.0 data frames, characterized in that, include: Obtain the string data to be sent, extract the content type identifier and redundancy features, perform adaptive compression encoding based on the redundancy features, and obtain the encoded data and compression ratio parameters; Maintain the historical compression ratio sliding window corresponding to the content type identifier, add the compression ratio parameter to the historical compression ratio sliding window, and calculate the compression ratio prediction value using the exponential weighted moving average algorithm; The time slot continuity requirement level is determined based on the content type identifier, and the time slot demand is calculated in combination with the compression ratio prediction value. A set of time slot resources is allocated on the bus time axis. The encoded data is divided into multiple data frames, and an inter-frame priority sequence is constructed for the data frames. The data frame is inserted into the transmission queue. The effective priority value of each data frame is calculated based on the inter-frame priority sequence and the waiting time. Arbitration sorting is performed according to the effective priority value. Under the constraints of the time slot resource set, transmission is performed sequentially according to the arbitration sorting result, specifically including: inserting the data frame into the transmission queue; obtaining the initial priority value and current waiting time of each data frame in the transmission queue; calculating the time slot urgency of the time slot resource corresponding to each data frame based on the time position of each time slot resource in the time slot resource set, wherein the time slot urgency represents the time interval between the start time and the current time of the time slot resource; determining the priority aging coefficient of each data frame according to the time slot urgency, wherein the priority aging coefficient increases as the time slot urgency decreases; calculating the priority aging increment by weighting the current waiting time and the corresponding priority aging coefficient; summing the initial priority value and the priority aging increment to obtain the effective priority value of each data frame; arbitrarily sorting the data frames in the transmission queue according to the effective priority value; and, under the constraints of the time slot resource set, extracting data frames from the transmission queue sequentially according to the arbitration sorting result and transmitting them, wherein when the transmission time of a data frame exceeds the time range of the corresponding time slot resource, the data frame is re-inserted into the transmission queue and the effective priority value is recalculated. The occupancy status of the time slot resource set is monitored. When the number of frames recalculated based on the actual compression effect is less than the estimated number of frames, the saved time slot resources are allocated to the target string data with the largest priority aging increment in the waiting queue through a priority adjustment mechanism.

2. The method according to claim 1, characterized in that, The steps of maintaining the historical compression ratio sliding window corresponding to the content type identifier, adding the compression ratio parameter to the historical compression ratio sliding window, and calculating the predicted compression ratio value include: Each content type identifier maintains an independent historical compression ratio sliding window, and the historical compression ratio sliding window uses a fixed-length circular queue structure to store historical compression ratio parameters; When a new compression ratio parameter arrives, the new compression ratio parameter is inserted at the end of the historical compression ratio sliding window. If the historical compression ratio sliding window is full, the compression ratio parameter at the head of the queue is automatically removed. Based on all compression ratio parameters in the historical compression ratio sliding window, the predicted compression ratio is calculated using an exponentially weighted moving average algorithm.

3. The method according to claim 1, characterized in that, The steps of determining the time slot continuity requirement level based on the content type identifier, calculating the time slot demand based on the compression ratio prediction value, and allocating a set of time slot resources on the bus time axis include: Data attribute features are obtained by parsing the content type identifier, time slot continuity requirement levels are determined based on the data attribute features, and corresponding time slot redundancy coefficients are obtained based on the time slot continuity requirement levels. The compression ratio standard deviation is calculated based on each compression ratio parameter in the historical compression ratio sliding window. When the compression ratio standard deviation exceeds a preset standard deviation threshold, the compression ratio fluctuation range is determined based on the predicted compression ratio value and the compression ratio standard deviation. The core time slot requirement is calculated based on the original data length of the string data to be sent, the lower limit of the compression ratio fluctuation range, and the time slot redundancy coefficient; the spare time slot requirement is calculated based on the original data length, the difference between the upper and lower limits of the compression ratio fluctuation range, and the time slot redundancy coefficient. Based on the time slot continuity requirement level, determine the time slot continuity constraints, find available time slot segments on the bus time axis that meet the time slot continuity constraints, allocate deterministic time slot resources for the core time slot demand in the available time slot segments, and allocate conditional reserved time slot resources for the spare time slot demand; the deterministic time slot resources and the conditional reserved time slot resources together constitute a time slot resource set.

4. The method according to claim 1, characterized in that, The steps of dividing the encoded data into multiple data frames and constructing an inter-frame priority sequence for the data frames include: Based on the total length of the encoded data and the payload capacity of the CAN2.0 data frame, the encoded data is divided into multiple data frames according to a preset framing strategy. Each data frame is assigned a frame sequence number and a frame type identifier, the frame type identifier distinguishing between the first frame, middle frames and the last frame, and the basic priority weight of each data frame is determined based on the content type identifier and the frame type identifier. Based on the time location and resource attributes of each time slot resource in the time slot resource set, a priority adjustment factor is set for each data frame, wherein the resource attributes reflect the degree of determinism of the time slot resource; The basic priority weight of each data frame is weighted and calculated with the corresponding priority adjustment factor to obtain the initial priority value of each data frame. An inter-frame priority sequence is then constructed according to the size relationship of the initial priority values.

5. The method according to claim 1, characterized in that, The step of monitoring the occupancy status of the time slot resource set and allocating the saved time slot resources to the target string data with the largest priority aging increment in the waiting queue through a priority adjustment mechanism when the number of frames recalculated based on the actual compression effect is less than the estimated number of frames includes: After the first frame of string data is sent, the actual compression ratio parameter of the first frame is obtained, and the compression gain deviation rate is calculated with the predicted compression ratio value. When the compression gain deviation rate exceeds the deviation threshold, the number of frames is recalculated based on the actual compression ratio parameter, and the time slot resources corresponding to the number of saved frames are calculated as the time window redundancy. Iterate through each string data in the waiting queue, calculate the matching degree between the estimated sending time and the redundancy of the time window, and select the string data with a matching degree exceeding the matching threshold and the largest priority aging increment as the target string data. Assign a priority boost increment to the target string data and increase its effective priority value; set an effective time window, after which the priority boost increment gradually decays to zero.

6. The method according to claim 5, characterized in that, It also includes a dynamic adjustment step for the framing strategy based on bus load prediction: The maintenance bus load monitoring sliding window counts the CAN bus occupancy rate. After the first frame of string data is sent, the expected transmission delay of the remaining data frames is calculated based on the CAN bus occupancy rate and the actual compression ratio parameter. The expected transmission delay is compared with the remaining time window of the time slot resource set. When the remaining time window is insufficient, the maximum number of frames that can be sent is recalculated and the frames are re-divided. The priority weight of the data frames after re-dividing is increased based on the time window tension. When the remaining time window is sufficient and the reduction in the number of frames exceeds the preset reduction threshold, the priority weight of the remaining data frames of the current string data is reduced, and the reduction is converted into priority transfer resources added to the global priority scheduling pool. Select the string data with the highest time urgency from the waiting queue and allocate the priority transfer resources to it to increase its effective priority value.

7. A CAN2.0 data frame real-time priority scheduling system, used to implement the method of any one of claims 1-6, characterized in that, include: The compression encoding module is used to acquire the string data to be sent, extract the content type identifier and redundancy features, perform adaptive compression encoding based on the redundancy features, and obtain the encoded data and compression ratio parameters; maintain the historical compression ratio sliding window corresponding to the content type identifier, add the compression ratio parameters to the historical compression ratio sliding window, and calculate the compression ratio prediction value; The time slot allocation module is used to determine the time slot continuity requirement level based on the content type identifier, calculate the time slot demand in combination with the compression ratio prediction value, and allocate a set of time slot resources on the bus time axis. The framing processing module is used to divide the encoded data into multiple data frames and construct an inter-frame priority sequence for the data frames. The arbitration sending module is used to insert the data frame into the sending queue, calculate the effective priority value of each data frame based on the inter-frame priority sequence and the waiting time, and perform arbitration sorting according to the effective priority value; Under the constraints of the time slot resource set, transmission is performed sequentially according to the arbitration sorting results; The resource monitoring and scheduling module is used to monitor the occupancy status of the time slot resource set. When the number of frames recalculated based on the actual compression effect is less than the estimated number of frames, the saved time slot resources are allocated to the target string data with the largest priority aging increment in the waiting queue through a priority adjustment mechanism.

8. An electronic device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to invoke instructions stored in the memory to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having computer program instructions stored thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and device for dispatching data in controller area network

    CN104009940A

  • Multi-level caching method and system based on CAN bus communication

    CN119788456A